[Javascript] Help please

Mikael Lindstrom mikael.lindstrom at nipsoft.se
Thu Jan 24 13:15:11 CST 2002


Correct me if I'm wrong but the line

var sport, times= prompt("Which sport like to do best, skiing, skydiving,
basketball, or football?", "Please choose one from the list")
prompt("How often do you do this, daily, weekly, or monthly?", "Please
choose one from the list")

It's is only variable times that gets an value, is it not !?

And then later on

switch(sport, times){

according to Netscapes Javscript language guide the syntax is
switch(expression) and an expression is explained:

"An expression is any valid set of literals, variables, operators, and
expressions that evaluates to a single value; the value can be a number, a
string, or a logical value."

A single value that is, so ... your switchstatement cannot work, if I
understand the manual correctly that is.

Regards

Mikael
  -----Original Message-----
  From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
Behalf Of Sherwithme1 at cs.com
  Sent: Thursday, January 24, 2002 7:52 PM
  To: javascript at LaTech.edu
  Subject: [Javascript] Help please


  Could you tell what I am doing wrong? I want both variables to be
evaluated using the switch statement. Why is it not working?
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

  <html>
  <head>
  <title>Switch</title>
  <div align = "center">
  </head>
  <body>
  <script language = "JavaScript1.2" type = "text/javascript">
  var sport, times= prompt("Which sport like to do best, skiing, skydiving,
basketball, or football?", "Please choose one from the list")
  prompt("How often do you do this, daily, weekly, or monthly?", "Please
choose one from the list")
  switch(sport, times){

  case "skiing" && "daily":
  document.write("You choose to ski daily");
  break;
  case "skiing" && "weekly":
  document.write("You choose to ski weekly");
  break;
  case "skiing" && "monthly":
  document.write("You choose to ski monthly");
  break;
  case"skydiving" && "daily":
  document.write("You choose to go skydiving daily");
  break;
  case"skydiving" && "weekly":
  document.write("You choose to go skydiving weekly");
  break;
  case"skydiving" && "monthly":
  document.write("You choose to go skydiving monthly");
  break;
  case"basketball" && "daily":
  document.write("You choose to play basketball daily");
  break;
  case"basketball" && "weekly":
  document.write("You choose to play basketball weekly");
  break;
  case"basketball" && "monthly":
  document.write("You choose to play basketball monthly");
  break;
  case"football" && "daily":
  document.write("You choose to play football daily");
  break;
  case"football" && "weekly":
  document.write("You choose to play football weekly");
  break;
  case"football" && "monthly":
  document.write("You choose to play football monthly");
  break;
  default:
  document.write("You didnt answer the questions!");
  break;
  }


  </script>
  </div>
  </body>
  </html>
  Thanks for your help
  Totally confused
  Sheryl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20020124/2a8d15d1/attachment.htm>


More information about the Javascript mailing list