http://www.htmlgoodies.com/primers/jsp/
var apples = 5;
alert('There are currently ' + apples + ' apples!');
if(isNaN(eaten)){
alert('You must enter a valid number of apples!');
eatApples();
} else if(eaten > apples){
alert('Sorry, but there are only ' + apples + ' apples. You can not eat ' + eaten + ' apples!');
eatApples();
} else if(eaten < 0){
alert('Sorry, but you can not eat less than 0 apples!');
eatApples();
} else {
apples -= eaten;
alert('Now there are only ' + apples + ' apples!');
if(apples > 0){
if(confirm('Would you like to eat more apples?')){
eatApples();
}
} else {
alert('All of the apples are now gone!');
}
}
}
var apples = 5;
alert('There are currently ' + apples + ' apples!');
if(isNaN(eaten)){
alert('You must enter a valid number of apples!');
eatApples();
} else if(eaten > apples){
alert('Sorry, but there are only ' + apples + ' apples. You can not eat ' + eaten + ' apples!');
eatApples();
} else if(eaten < 0){
alert('Sorry, but you can not eat less than 0 apples!');
eatApples();
} else {
apples -= eaten;
alert('Now there are only ' + apples + ' apples!');
if(apples > 0){
if(confirm('Would you like to eat more apples?')){
eatApples();
}
} else {
alert('All of the apples are now gone!');
}
}
}

浙公网安备 33010602011771号