|
Shouldn't the comparisons look something like,
if (a == b)
{
}
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
As you suggest, the '=' should be '=='. As is
if (randomNum = 0) sets randomNum to 0 and the 'if' effectively becomes 'if (0)' which is a falsy result (not false, but treated false), so it carries on. Then
else if (randomNum = 1) sets randomNum to 1 and the 'if' effectively becomes 'if (1)' which is a truthy result (not true, buth treated as true) so it succeeds.
Many people may jump up and down and say it shows what a dreadful language JavaScript is; but the same thing is valid in many other languages, e.g. C, C#, Java.
|
|
|
|
|
Got it thnx!
modified 29-Aug-22 21:01pm.
|
|
|
|
|
You need to show the code you have for people to help you. No one here is going to write your complete assignment.
|
|
|
|
|
function colorSelector (colorCode) {
let randomNumber = Math.floor((Math.random() * 100));
if (randomNumber < 10) {
console.log("green");
}
else if (randomNumber >= 10 && randomNumber < 19) {
console.log("yellow");
}
else if (randomNumber > 19) {
console.log("blue");
}
return (randomNumber);
}
console.log(colorCode);
This is how far I got. Im confused what should be inside the function and what should we outside. Im also not sure if im using the return operator the right way.
modified 29-Aug-22 21:01pm.
|
|
|
|
|
Your code is quite confused, and confusing. You specify that the function takes an input parameter named colorCode , but you never refer to it in the function. Your if/else clauses include the variable condition which is never defined anywhere. Finally you return the randomNumber for no reason I can see.
- The function does not need an input parameter, unless you want to pass it a random number. Assuming yo do not, then generate the number as the first step.
- The if statements only need to be as follows
- 1: If the value is less than 10 set colorCode to "green"
- 2: Else If it is less than 50 set colorCode to "yellow" (we already know it is not less than 10)
- 3: Else set it to "blue" (it must be 50 or greater)
- return colorCode to the caller of the function.
modified 16-Jul-22 7:11am.
|
|
|
|
|
So, you nearly there.
function colorSelector (colorCode) {
let randomNumber = Math.floor((Math.random() * 100));
if (randomNumber < 10) {
console.log("green");
}
else if (randomNumber >= 10 && randomNumber < 19) {
console.log("yellow");
}
else if (randomNumber > 19) {
console.log("blue");
}
return (randomNumber);
}
console.log(colorSelector(50)); I got a warning that "colorCode" doesn't exist. And true, it doesn't. That makes it confusing, because there's two options. Let's forget them for a second. Try the code I gave you, vary the number. It writes to the console also.
Member 15708114 wrote: I know that I have to use the Math.floor and Math.random to create a random number and the if and return operators but I think im messing up the order. Please help anyone. You creating a random number inside the function. You want to "pass" it to the function as an argument.
So you don't see where on thing starts and the other ends? It's called "scope". Ask your teacher. Once clear, ask to step.
It executes one line, shows result in debug. That way you see how the computer "steps" through your instructions.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
else if (randomNumber >= 10 && randomNumber < 19) {
^^^^^^^^^^^^^^^^^^
We know it is >= 10 from the previous if statement.
else if (randomNumber > 19) {
And it this point it must be > 19, so all that is needed is a simple else clause.
|
|
|
|
|
Richard MacCutchan wrote: And it this point it must be > 19, so all that is needed is a simple else clause. That's the advanced course. I somehow think his teacher might have escaped that.
It's a beginner.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
But that is nothing to do with programming, it is simple mathematical logic.
|
|
|
|
|
Correct. It got to do with education.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
There was no requirement for a "random number"; the requirement was for a function that accepts a number.
And that function could be tested any number of ways; usually with a "console app" that accepts a number as input from the user and then uses that number in that function, and displaying the result.
if ( n < 10 ) {
else if ( n <= 50 ) {
} else {
}
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Hello,
I am having a JSON Object as below in Node JS editor:
{"replyType":"queryDataRqst","requestId":169,"errCode" ,"options" ,"ccuSec":1657531129,"ccuNanosec":257000000,"replyData":[["IncidentStatusLine","\"machineId\":1111,\"incidentTidx\":101016,\"helpTidx\":101017,\"componentTidx\":100100,\"type\":2,\"state\":2,\"priority\":10,\"args\":{\"userData\":[{\"_d\":858993459,\"stringTidxValue\" ,\"longValue\":-634515298,\"realValue\" .0,\"nullValue\" },\"_d\":286331153,\"stringTidxValue\" ,\"longValue\" ,\"realValue\" .0,\"nullValue\" },\"_d\":286331153,\"stringTidxValue\" ,\"longValue\" ,\"realValue\" .0,\"nullValue\" },\"_d\":286331153,\"stringTidxValue\" ,\"longValue\" ,\"realValue\" .0,\"nullValue\" },\"_d\":286331153,\"stringTidxValue\" ,\"longValue\" ,\"realValue\" .0,\"nullValue\" },\"_d\":286331153,\"stringTidxValue\" ,\"longValue\" ,\"realValue\" .0,\"nullValue\" }]},\"text\":\"\",\"sequencenum\":287,\"timestamp\":1657522757472000000,\"wintimestamp\":133019963574720000,\"hashval\":-492839581,\"hideable\":false}"]]}
Now I need extract the value from the above JSON String as below:
{"userData":[{"_d":858993459,"stringTidxValue" ,"longValue":-634515298,"realValue" .0,"nullValue" },"_d":286331153,"stringTidxValue" ,"longValue" ,"realValue" .0,"nullValue" },"_d":286331153,"stringTidxValue" ,"longValue" ,"realValue" .0,"nullValue" },"_d":286331153,"stringTidxValue" ,"longValue" ,"realValue" .0,"nullValue" },"_d":286331153,"stringTidxValue" ,"longValue" ,"realValue" .0,"nullValue" },"_d":286331153,"stringTidxValue" ,"longValue" ,"realValue" .0,"nullValue" }]}
How to get this value using Node JS.
Thanks,
Uday
|
|
|
|
|
|
I'm using WebView2 to display data in my app. If I send a string literal it works fine. But if I send a value in a variable I get nothing.
This works:
wb.ExecuteScriptAsync("document.body.innerHTML=" & ChrW(39) & "HELLO" & ChrW(39))
This doesn't ("lStr" is my string variable):
wb.ExecuteScriptAsync("document.body.innerHTML=" & ChrW(39) & lStr & ChrW(39))
I assume I'm doing something wrong here. Any advice is appreciated.
Sometimes the true reward for completing a task is not the money, but instead the satisfaction of a job well done. But it's usually the money.
|
|
|
|
|
That's going to depend on the content of your variable, which we can't see.
For example, if the variable contains a single quote or any newline characters, your script will end up with an "unterminated string literal" error.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Could possibly contain quotes but no newline chars. I was trying to give my old spell checker a facelift. I wanted to use the WebView2 for the error text ("Not In Dictionary"). It's one line from the text editor with the error highlighted. So I'd need to send it the error start/end positions plus tell it to scroll to that position. All easily done if I could figure out how to send it a value in a variable.
Sometimes the true reward for completing a task is not the money, but instead the satisfaction of a job well done. But it's usually the money.
|
|
|
|
|
As I said, you'll need to ensure the value is properly encoded.
Assuming you're running .NET Framework 4.7.2 or later, .NET Core, or .NET 5+, then you can use the System.Text.Json package[^] to encode the string:
wb.ExecuteScriptAsync("document.body.innerHTML=" & System.Text.Json.JsonSerializer.Serialize(lStr)) For older frameworks, use the Json.NET[^] package.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you!
Sometimes the true reward for completing a task is not the money, but instead the satisfaction of a job well done. But it's usually the money.
|
|
|
|
|
Hi,
New here. Anyway I'm working on a project and I'm placing some text over some images. All is good with that.
However I only want to rotate the text 35 degrees but I can't figure how to do that in Javascript.
Here is how I'm displaying the text -
const ctxt = canvas.getContext('2d');
ctxt.fillStyle = 'red';
ctxt.font = '40px Brush Script MT';
ctxt.fillText('TEST',200,178);
Thanks.
|
|
|
|
|
The canvas uses a transformation matrix and it has a few functions for manipulating it.
Here is a 35-degree rotation:
const ctxt = canvas.getContext('2d');
ctxt.fillStyle = 'red';
ctxt.font = '40px Brush Script MT';
const tm = ctxt.measureText('TEST');
ctxt.translate(200 + tm.width / 2, 178);
ctxt.rotate(35 * 3.14159 / 180);
ctxt.translate(-(200 + tm.width / 2), -178);
ctxt.fillText('TEST',200,178);
ctxt.resetTransform();
|
|
|
|
|
Awesome! Just what I needed. Thanks!
|
|
|
|
|
I want to load image dynamically from database in popup form
how to receive or integred databending in JS script with laravel8 ?
<script type="text/javascript">
function getValues(){
document.getElementById('txt1').value=imageName;
var path = '{{asset(storage/images/imageName)}}' ;
document.getElementById('img').src=path ;
}
</script>
>> In HTML <<
<input type="text" name="txt1" id="txt1" />
<img src="default.jpg" name="img" id="img" >
>> ERROR <<
<pre>Use of undefined constant storage - assumed 'storage' (this will throw an Error in a future version of PHP) (View: C:\xampp\htdocs\Ecommerce-Front\resources\views\popup.blade.php)
|
|
|
|
|
hi am geting this error
Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: <h2 />. Did you accidentally export a JSX literal instead of a component?
at App
console.<computed> @ index.js:1
printWarning @ react-jsx-dev-runtime.development.js:97
error @ react-jsx-dev-runtime.development.js:71
jsxWithValidation @ react-jsx-dev-runtime.development.js:1242
App @ App.js:7
renderWithHooks @ react-dom.development.js:16175
mountIndeterminateComponent @ react-dom.development.js:20913
beginWork @ react-dom.development.js:22416
beginWork$1 @ react-dom.development.js:27381
performUnitOfWork @ react-dom.development.js:26513
workLoopSync @ react-dom.development.js:26422
renderRootSync @ react-dom.development.js:26390
performConcurrentWorkOnRoot @ react-dom.development.js:25694
workLoop @ scheduler.development.js:266
flushWork @ scheduler.development.js:239
performWorkUntilDeadline @ scheduler.development.js:533
run @ setImmediate.js:40
runIfPresent @ setImmediate.js:69
onGlobalMessage @ setImmediate.js:109
postMessage (async)
registerImmediate @ setImmediate.js:120
setImmediate @ setImmediate.js:27
schedulePerformWorkUntilDeadline @ scheduler.development.js:564
requestHostCallback @ scheduler.development.js:588
unstable_scheduleCallback @ scheduler.development.js:441
scheduleCallback$1 @ react-dom.development.js:27491
ensureRootIsScheduled @ react-dom.development.js:25639
scheduleUpdateOnFiber @ react-dom.development.js:25428
updateContainer @ react-dom.development.js:28804
push../node_modules/react-dom/cjs/react-dom.development.js.ReactDOMHydrationRoot.render.ReactDOMRoot.render @ react-dom.development.js:29216
(anonymous) @ index.js:7
./src/index.js @ index.js:8
__webpack_require__ @ bootstrap:851
fn @ bootstrap:150
1 @ index.js:8
__webpack_require__ @ bootstrap:851
checkDeferredModules @ bootstrap:45
webpackJsonpCallback @ bootstrap:32
(anonymous) @ main.chunk.js:1
react-dom.development.js:28389 Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of `App`.
at createFiberFromTypeAndProps (react-dom.development.js:28389:1)
at createFiberFromElement (react-dom.development.js:28415:1)
at createChild (react-dom.development.js:14979:1)
at reconcileChildrenArray (react-dom.development.js:15274:1)
at reconcileChildFibers (react-dom.development.js:15691:1)
at reconcileChildren (react-dom.development.js:19964:1)
at updateHostComponent$1 (react-dom.development.js:20733:1)
at beginWork (react-dom.development.js:22447:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:4161:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:4210:1)
at invokeGuardedCallback (react-dom.development.js:4274:1)
at beginWork$1 (react-dom.development.js:27405:1)
at performUnitOfWork (react-dom.development.js:26513:1)
at workLoopSync (react-dom.development.js:26422:1)
at renderRootSync (react-dom.development.js:26390:1)
at performConcurrentWorkOnRoot (react-dom.development.js:25694:1)
at workLoop (scheduler.development.js:266:1)
at flushWork (scheduler.development.js:239:1)
at performWorkUntilDeadline (scheduler.development.js:533:1)
at run (setImmediate.js:40:1)
at runIfPresent (setImmediate.js:69:1)
at onGlobalMessage (setImmediate.js:109:1)
createFiberFromTypeAndProps @ react-dom.development.js:28389
createFiberFromElement @ react-dom.development.js:28415
createChild @ react-dom.development.js:14979
reconcileChildrenArray @ react-dom.development.js:15274
reconcileChildFibers @ react-dom.development.js:15691
reconcileChildren @ react-dom.development.js:19964
updateHostComponent$1 @ react-dom.development.js:20733
beginWork @ react-dom.development.js:22447
callCallback @ react-dom.development.js:4161
invokeGuardedCallbackDev @ react-dom.development.js:4210
invokeGuardedCallback @ react-dom.development.js:4274
beginWork$1 @ react-dom.development.js:27405
performUnitOfWork @ react-dom.development.js:26513
workLoopSync @ react-dom.development.js:26422
renderRootSync @ react-dom.development.js:26390
performConcurrentWorkOnRoot @ react-dom.development.js:25694
workLoop @ scheduler.development.js:266
flushWork @ scheduler.development.js:239
performWorkUntilDeadline @ scheduler.development.js:533
run @ setImmediate.js:40
runIfPresent @ setImmediate.js:69
onGlobalMessage @ setImmediate.js:109
postMessage (async)
registerImmediate @ setImmediate.js:120
setImmediate @ setImmediate.js:27
schedulePerformWorkUntilDeadline @ scheduler.development.js:564
requestHostCallback @ scheduler.development.js:588
unstable_scheduleCallback @ scheduler.development.js:441
scheduleCallback$1 @ react-dom.development.js:27491
ensureRootIsScheduled @ react-dom.development.js:25639
scheduleUpdateOnFiber @ react-dom.development.js:25428
updateContainer @ react-dom.development.js:28804
push../node_modules/react-dom/cjs/react-dom.development.js.ReactDOMHydrationRoot.render.ReactDOMRoot.render @ react-dom.development.js:29216
(anonymous) @ index.js:7
./src/index.js @ index.js:8
__webpack_require__ @ bootstrap:851
fn @ bootstrap:150
1 @ index.js:8
__webpack_require__ @ bootstrap:851
checkDeferredModules @ bootstrap:45
webpackJsonpCallback @ bootstrap:32
(anonymous) @ main.chunk.js:1
index.js:1 Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: <h2 />. Did you accidentally export a JSX literal instead of a component?
at App
console.<computed> @ index.js:1
printWarning @ react-jsx-dev-runtime.development.js:97
error @ react-jsx-dev-runtime.development.js:71
jsxWithValidation @ react-jsx-dev-runtime.development.js:1242
App @ App.js:7
renderWithHooks @ react-dom.development.js:16175
mountIndeterminateComponent @ react-dom.development.js:20913
beginWork @ react-dom.development.js:22416
beginWork$1 @ react-dom.development.js:27381
performUnitOfWork @ react-dom.development.js:26513
workLoopSync @ react-dom.development.js:26422
renderRootSync @ react-dom.development.js:26390
recoverFromConcurrentError @ react-dom.development.js:25806
performConcurrentWorkOnRoot @ react-dom.development.js:25706
workLoop @ scheduler.development.js:266
flushWork @ scheduler.development.js:239
performWorkUntilDeadline @ scheduler.development.js:533
run @ setImmediate.js:40
runIfPresent @ setImmediate.js:69
onGlobalMessage @ setImmediate.js:109
postMessage (async)
registerImmediate @ setImmediate.js:120
setImmediate @ setImmediate.js:27
schedulePerformWorkUntilDeadline @ scheduler.development.js:564
requestHostCallback @ scheduler.development.js:588
unstable_scheduleCallback @ scheduler.development.js:441
scheduleCallback$1 @ react-dom.development.js:27491
ensureRootIsScheduled @ react-dom.development.js:25639
scheduleUpdateOnFiber @ react-dom.development.js:25428
updateContainer @ react-dom.development.js:28804
push../node_modules/react-dom/cjs/react-dom.development.js.ReactDOMHydrationRoot.render.ReactDOMRoot.render @ react-dom.development.js:29216
(anonymous) @ index.js:7
./src/index.js @ index.js:8
__webpack_require__ @ bootstrap:851
fn @ bootstrap:150
1 @ index.js:8
__webpack_require__ @ bootstrap:851
checkDeferredModules @ bootstrap:45
webpackJsonpCallback @ bootstrap:32
(anonymous) @ main.chunk.js:1
react-dom.development.js:28389 Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of `App`.
at createFiberFromTypeAndProps (react-dom.development.js:28389:1)
at createFiberFromElement (react-dom.development.js:28415:1)
at createChild (react-dom.development.js:14979:1)
at reconcileChildrenArray (react-dom.development.js:15274:1)
at reconcileChildFibers (react-dom.development.js:15691:1)
at reconcileChildren (react-dom.development.js:19964:1)
at updateHostComponent$1 (react-dom.development.js:20733:1)
at beginWork (react-dom.development.js:22447:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:4161:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:4210:1)
at invokeGuardedCallback (react-dom.development.js:4274:1)
at beginWork$1 (react-dom.development.js:27405:1)
at performUnitOfWork (react-dom.development.js:26513:1)
at workLoopSync (react-dom.development.js:26422:1)
at renderRootSync (react-dom.development.js:26390:1)
at recoverFromConcurrentError (react-dom.development.js:25806:1)
at performConcurrentWorkOnRoot (react-dom.development.js:25706:1)
at workLoop (scheduler.development.js:266:1)
at flushWork (scheduler.development.js:239:1)
at performWorkUntilDeadline (scheduler.development.js:533:1)
at run (
this my index.js
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
|
|
|
|
|
IF ANYONE Can help me get through this I will pay!!!!!!!!!!!!
Server Error in '/' Application.
contact With Id = 00000000-0000-0000-0000-000000000000 Does Not Exist
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: contact With Id = 00000000-0000-0000-0000-000000000000 Does Not Exist
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[FaultException`1: contact With Id = 00000000-0000-0000-0000-000000000000 Does Not Exist]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +14833454
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +386
Microsoft.Xrm.Sdk.IOrganizationService.Execute(OrganizationRequest request) +0
Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.ExecuteCore(OrganizationRequest request) +797
Microsoft.Xrm.Client.Services.InnerOrganizationService.UsingService(Func`2 action) +127
Microsoft.Xrm.Client.Services.CachedOrganizationService.InnerExecute(OrganizationRequest request) +139
Microsoft.Xrm.Client.Services.OrganizationServiceCache.InnerExecute(TRequest query, Func`2 execute, Func`2 selector) +21
Microsoft.Xrm.Client.Caching.<>c__DisplayClass6`1.<get>b__5(String key) +27
Microsoft.Xrm.Client.Threading.<>c__DisplayClass5`1.<get>b__3() +49
Microsoft.Xrm.Client.Threading.MutexExtensions.Lock(String key, Int32 millisecondsTimeout, Action`1 action) +110
Microsoft.Xrm.Client.Threading.LockProvider.Get(String key, Int32 millisecondsTimeout, Func`2 loadFromCache, Func`2 loadFromService) +237
Microsoft.Xrm.Client.Services.OrganizationServiceCache.LookupAndInsert(TRequest query, Func`2 execute, Func`2 selector, String selectorCacheKey) +375
Microsoft.Xrm.Client.Services.OrganizationServiceCache.InnerExecute(TRequest request, Func`2 execute, Func`2 selector, String selectorCacheKey) +191
Microsoft.Xrm.Client.Services.CachedOrganizationService.Execute(OrganizationRequest request, Func`2 selector, String selectorCacheKey) +227
Microsoft.Xrm.Client.Services.CachedOrganizationService.Execute(OrganizationRequest request) +162
Microsoft.Xrm.Client.Services.CachedOrganizationService.Retrieve(String entityName, Guid id, ColumnSet columnSet) +154
PSEGPortal.ApplicationService.GetContactInfo(Guid contactId, CrmOrganizationServiceContext service) +101
PSEGPortal.ApplicationService.GetPartnerInfo(Guid accountId, Guid olaId) +521
PSEGPortal.CustomerInformation.loadApplication(String lp, String ola) +726
System.Web.UI.Control.OnLoad(EventArgs e) +106
System.Web.UI.Control.LoadRecursive() +68
System.Web.UI.Control.LoadRecursive() +162
System.Web.UI.Control.LoadRecursive() +162
System.Web.UI.Control.LoadRecursive() +162
System.Web.UI.Control.LoadRecursive() +162
System.Web.UI.Control.LoadRecursive() +162
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3785
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3930.0
|
|
|
|
|