Click here to Skip to main content
15,434,813 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionI need help with a task Pin
User 1567076221-Jul-22 11:35
MemberUser 1567076221-Jul-22 11:35 
AnswerRe: I need help with a task Pin
jeron121-Jul-22 11:56
Memberjeron121-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
MemberUser 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
MemberUser 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
Memberjanaswamy uday12-Jul-22 7:23 
AnswerRe: extract value from json Object in Node JS Pin
Ben Code15-Aug-22 23:59
MemberBen Code15-Aug-22 23:59 
QuestionWebView2 - Send Script with a Value Pin
Alan Burkhart5-Jul-22 9:28
MemberAlan 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
MemberAlan 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
MemberAlan Burkhart8-Jul-22 0:24 
QuestionRotate text Pin
Rockallica13-Jun-22 13:57
MemberRockallica13-Jun-22 13:57 
AnswerRe: Rotate text Pin
Graham Breach13-Jun-22 20:58
MemberGraham Breach13-Jun-22 20:58 
GeneralRe: Rotate text Pin
Rockallica14-Jun-22 8:38
MemberRockallica14-Jun-22 8:38 
QuestionLaravel 8 integred databending in JS Pin
paradox0210-Jun-22 7:13
Memberparadox0210-Jun-22 7:13 
Questionissue with my app Pin
james michael May20225-Jun-22 2:27
Memberjames michael May20225-Jun-22 2:27 

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.