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?
3 Answers
+ 7
Turn your main portion into a function
+ 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;
}
}
};
0
How would I do that?