English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

var day = prompt("What day is it?","")
if (day == Saturday || day == Sunday)
alert("Enjoy your Weekend")

2007-03-28 08:09:18 · 2 answers · asked by judi s 1 in Computers & Internet Programming & Design

2 answers

Prompt returns a string. You need to encapsulate them in quotes (day == "Saturday"). You should also eliminate case-sensitivity by using day.toLowerCase() == "saturday"

What you have done in your code example is ask whether the value of the variable "day" is equal to the value of the variable "Saturday". Obviously since no such variable exists, this is invalid. Literal strings must be enclosed with quotes.

2007-03-28 08:17:38 · answer #1 · answered by Rex M 6 · 0 2

You either need to add statements like this before you code:
var Saturday="Saturday";
var Sunday="Sunday";

or add the quotes to change the if statement to compare to strings instead of variables.
if (day=="Saturday" || day=="Sunday")

2007-03-28 15:20:02 · answer #2 · answered by David G 2 · 2 1

fedest.com, questions and answers