The if statement for JAVASCRIPT isn't working. | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

The if statement for JAVASCRIPT isn't working.

I want it to display an alert depending on the input of a prompt, but it only displays the first one, both, or none. I tried the else if and it didn't work. I couldn't find this problem in the current discussion, or the answere in the lessons or intro to JS. Please Help

14th Jun 2023, 12:04 PM
Paxton Programer
4 Antworten
+ 8
Share your code link here and detailed description of what you are working on.
14th Jun 2023, 12:06 PM
D Shah 🎯⏳️
D Shah 🎯⏳️ - avatar
+ 1
let x = 5; if (x > 0) { console.log("x is positive"); } else { console.log("x is not positive"); } the condition x > 0 is true, so the code within the first block will be executed and “x is positive” will be logged to the console. If your if statement isn’t working, there could be a few reasons.
17th Jun 2023, 7:04 AM
Vaibhav
Vaibhav - avatar
0
Var select = prompt("type A for option 1 type B for option 2") If(select === "A"){ alert("You have selected option 1") } If (select === "B"){ alert("you have selected option 2") }
15th Jun 2023, 11:41 AM
Paxton Programer
0
Just updating: it must have been a glitch because it is working now
15th Jun 2023, 11:46 AM
Paxton Programer