var reply = prompt("Do you want information on Stars(S) or Planets(P)?", "");
if(reply == "Stars") {
What if the user types "stars" or "planets"?
Code:
if (/^p/i.test(reply) { // if the first letter of reply is p (case insensitive)
alert ("Planets");
reply = "p";
}
if (/^s/i.test(reply)) { // if the first letter of reply is s (case insensitive)
alert ("Stars");
reply = "s";
}
else {
alert ("Please enter P(lants) or S(tars)");
}
prompt("Type in a number between 1 and 8, and I will tell you the name of the planet. ");
What if the user types "99" or "Mickey Mouse"?
A good proportion of any computer code consists of user input validation.
This should point you in the right direction, but still a lot to do:-
Code:
var reply = "s"; // obtained from user prompt;
var value = 3; // obtained from user prompt
if (reply == "s") {
switch(value) {
case 1: alert( "The name of the star that is 1st closest to the Earth is Proxima Centauri"); break;
case 2: alert("The name of the star that is 2nd closest to the Earth is Alpha Centauri A) "); break;
case 3: alert("The name of the star that is 3rd closest to the Earth is Alpha Centauri B"); break;
default : alert ("This is the default message");
}
}
if (reply == "p") {
switch (value)
}