漫漫技术人生路

C#

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
http://www.htmlgoodies.com/primers/jsp/
var
apples = 5;


function eatApples(){
    alert('There are currently ' + apples + ' apples!');


    var eat = prompt('How many apples would you like to eat?', '1');


    var eaten = parseInt(eat);
    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!');
        }
    }
}
posted on 2006-12-05 16:40  javaca88  阅读(176)  评论(0)    收藏  举报