Click here to Skip to main content
15,886,519 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: I need help in defining and calling Static variable in Typescript. Pin
Jeremy Falcon26-Oct-22 11:41
professionalJeremy Falcon26-Oct-22 11:41 
QuestionNew to Coding Pin
John Wiser25-Jul-22 3:05
John Wiser25-Jul-22 3:05 
AnswerRe: New to Coding Pin
Richard MacCutchan25-Jul-22 3:10
mveRichard MacCutchan25-Jul-22 3:10 
GeneralRe: New to Coding Pin
John Wiser25-Jul-22 9:44
John Wiser25-Jul-22 9:44 
AnswerRe: New to Coding Pin
Jeremy Falcon26-Oct-22 11:49
professionalJeremy Falcon26-Oct-22 11:49 
QuestionI need help with a task Pin
User 1567076221-Jul-22 11:35
User 1567076221-Jul-22 11:35 
AnswerRe: I need help with a task Pin
jeron121-Jul-22 11:56
jeron121-Jul-22 11:56 
GeneralRe: I need help with a task Pin
jsc4225-Jul-22 4:11
professionaljsc4225-Jul-22 4:11 
QuestionI need help with an Javascript exercise! Pin
User 1567076215-Jul-22 20:39
User 1567076215-Jul-22 20:39 
GeneralRe: I need help with an Javascript exercise! Pin
Richard MacCutchan15-Jul-22 21:29
mveRichard MacCutchan15-Jul-22 21:29 
GeneralRe: I need help with an Javascript exercise! Pin
User 1567076215-Jul-22 22:59
User 1567076215-Jul-22 22:59 
GeneralRe: I need help with an Javascript exercise! Pin
Richard MacCutchan15-Jul-22 23:09
mveRichard MacCutchan15-Jul-22 23:09 
GeneralRe: I need help with an Javascript exercise! Pin
Eddy Vluggen16-Jul-22 3:53
professionalEddy Vluggen16-Jul-22 3:53 
So, you nearly there.

C#
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 Suspicious | :suss:
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

GeneralRe: I need help with an Javascript exercise! Pin
Richard MacCutchan16-Jul-22 4:18
mveRichard MacCutchan16-Jul-22 4:18 
GeneralRe: I need help with an Javascript exercise! Pin
Eddy Vluggen16-Jul-22 4:46
professionalEddy Vluggen16-Jul-22 4:46 
GeneralRe: I need help with an Javascript exercise! Pin
Richard MacCutchan16-Jul-22 4:51
mveRichard MacCutchan16-Jul-22 4:51 
GeneralRe: I need help with an Javascript exercise! Pin
Eddy Vluggen16-Jul-22 5:00
professionalEddy Vluggen16-Jul-22 5:00 
AnswerRe: I need help with an Javascript exercise! Pin
Gerry Schmitz16-Jul-22 5:49
mveGerry Schmitz16-Jul-22 5:49 
Questionextract value from json Object in Node JS Pin
janaswamy uday12-Jul-22 7:23
janaswamy uday12-Jul-22 7:23 
AnswerRe: extract value from json Object in Node JS Pin
Ben Code15-Aug-22 23:59
Ben Code15-Aug-22 23:59 
QuestionWebView2 - Send Script with a Value Pin
Alan Burkhart5-Jul-22 9:28
Alan Burkhart5-Jul-22 9:28 
AnswerRe: WebView2 - Send Script with a Value Pin
Richard Deeming7-Jul-22 2:19
mveRichard Deeming7-Jul-22 2:19 
GeneralRe: WebView2 - Send Script with a Value Pin
Alan Burkhart7-Jul-22 14:05
Alan Burkhart7-Jul-22 14:05 
GeneralRe: WebView2 - Send Script with a Value Pin
Richard Deeming7-Jul-22 21:42
mveRichard Deeming7-Jul-22 21:42 
GeneralRe: WebView2 - Send Script with a Value Pin
Alan Burkhart8-Jul-22 0:24
Alan Burkhart8-Jul-22 0:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.