Don't like ads? PRO users don't see any ads ;-)
Guest

assignment 2 js

By: a guest on Jun 22nd, 2012  |  syntax: JavaScript  |  size: 0.91 KB  |  hits: 38  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. var fav
  2. var lfav
  3. var same
  4.  
  5.  
  6. onload=question();
  7. alert("i am working");
  8.  
  9.  
  10. if(fav===chocolate || fav===Chocolate){
  11.         same=0;
  12.         }
  13. else{  
  14.         if(lfav===vanilla || lfav===Vanilla){
  15.                 same=1;
  16.                 }
  17.         else{
  18.                 same=2;
  19.                 }
  20.         }
  21.        
  22.  
  23.        
  24. switch(same){
  25.         case 0:
  26.                 alert("We have the same favorite");
  27.                 break;
  28.         case 1:
  29.                 alert("We have the same least favorite");
  30.                 break;
  31.         case 2:
  32.                 alert("We have nothing in common");
  33.                 break;
  34.         }
  35.        
  36. function question(){
  37.         fav=prompt("What is your favorite flavor of ice cream?", "");
  38.         if(fav==""){
  39.                 alert("Please enter a flavor");
  40.                 question();
  41.                 }
  42.         else{
  43.                 alert("Your favorite flavor is " + fav + ".");
  44.                 question2();
  45.                 }
  46.         }
  47.        
  48. function question2(){
  49.         lfav=prompt("What is your least favorite flavor of ice cream?", "");
  50.         if(lfav==""){
  51.                 alert("Please enter a flavor");
  52.                 question2();
  53.                 }
  54.         else{
  55.                 alert("Your least favorite flavor is " + lfav + ".");
  56.                 return;
  57.                 }
  58.         }