|
W3Schools Online Web Tutorials[^] is probably the best site for learning web based technologies. So go to the Javascript section and follow it through, it will explain everything.
|
|
|
|
|
|
First, welcome to web development. It's an industry that only continues to grow. We'd be happy to help with specific questions.
As far as just getting started with all the concepts, nothing beats a good book. The website linked is great, but usually book authors take much more time to explain things.
I wish I could recommend a good current book, but I started web development back in the 90s. That crap is out of print by now I'm sure. But, once you do get the concepts, I can recommend a reference website. The Mozilla foundation (same peeps that make FireFox) have an online resource called the Mozilla Developer Network (MDN).
Learn web development | MDN[^]
It will literally be one of the best reference sites to use, once you get the concepts down.
Jeremy Falcon
|
|
|
|
|
Got it! Thnx
modified 29-Aug-22 21:01pm.
|
|
|
|
|
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();
|
|
|
|
|