Why doesn't this code work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why doesn't this code work?

This is pretty much what my code is like: window.onload = alert("message"); var Main = prompt("Choose ONE or TWO").doUpperCase(); var ChoiceOne = alert("Correct"); var ChoiceTwo = alert("Incorrect"); Main; case(one) { ChoiceOne; } case(two) { ChoiceTwo; } Html and Css are both completely empty. When I run this, nothing happens at all. Can someone please tell me how to fix this?

10th Sep 2017, 10:24 PM
Zephyr
Zephyr - avatar
3 Answers
+ 7
Turn your main portion into a function
10th Sep 2017, 10:29 PM
Manual
Manual - avatar
+ 3
There are too many issues with what you have here, so i'm just gonna post code that does what I think you're trying to do and if you have any further questions after reviewing and comparing the differences between the two just ask them here in this thread. window.onload = alert("message"); var ans; var Main = function() { ans = prompt("Choose ONE or TWO").toUpperCase() }; var ChoiceOne = function() { alert("Correct") }; var ChoiceTwo = function() { alert("Incorrect") }; Main(); switch(ans) { case "ONE": { ChoiceOne(); break; } case "TWO": { ChoiceTwo(); break; } } Or: window.onload = function() { alert("message"); var Main = prompt("Choose ONE or TWO").toUpperCase(); var ChoiceOne = function() { alert("Correct") }; var ChoiceTwo = function() { alert("Incorrect") }; switch(Main) { case "ONE": { ChoiceOne(); break; } case "TWO": { ChoiceTwo(); break; } } };
10th Sep 2017, 11:08 PM
ChaoticDawg
ChaoticDawg - avatar
0
How would I do that?
10th Sep 2017, 10:38 PM
Zephyr
Zephyr - avatar