
assignment 2 js
By: a guest on
Jun 22nd, 2012 | syntax:
JavaScript | size: 0.91 KB | hits: 38 | expires: Never
var fav
var lfav
var same
onload=question();
alert("i am working");
if(fav===chocolate || fav===Chocolate){
same=0;
}
else{
if(lfav===vanilla || lfav===Vanilla){
same=1;
}
else{
same=2;
}
}
switch(same){
case 0:
alert("We have the same favorite");
break;
case 1:
alert("We have the same least favorite");
break;
case 2:
alert("We have nothing in common");
break;
}
function question(){
fav=prompt("What is your favorite flavor of ice cream?", "");
if(fav==""){
alert("Please enter a flavor");
question();
}
else{
alert("Your favorite flavor is " + fav + ".");
question2();
}
}
function question2(){
lfav=prompt("What is your least favorite flavor of ice cream?", "");
if(lfav==""){
alert("Please enter a flavor");
question2();
}
else{
alert("Your least favorite flavor is " + lfav + ".");
return;
}
}