This forum is now read-only. Please use our new forums! Go to forums
I'm not too sure where I should put my if/else statements :$
Hey, I’m just not too sure where my if/else statement should go within the block of code :\ Could someone help me with the structure my code should follow?
var user = prompt(“What you want to do”).toUpperCase(); switch(user){ case’kill’: console.log(“Okay”); break; case’Attack’: console.log(“Sure”); break; case’Nothing’: console.log(“are you sure?”); break; default: console.log(“try, Kill, Attack or Nothing”); }
Thanks!!
Answer 5418b96380ff33a2000008da
The if/else can go anywhere. Instead of 1 switch you could use multiple if’s. Or you show 2 prompts and use an if/else inside the cases to check for the 2nd prompt’s answer.
btw.: you convert the input stored in the variable user to upper case. so ur cases have to be all upper case. Like this: “KILL”, “ATTACK”, “SURE”, “NOTHING”.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency