猿问

使用 JavaScript Mad Libs Challenge 进行 DRY 编程

我是编程新手。


我知道我可以使用函数和循环来避免重复此代码,但我需要帮助。任何人?


var questions = 3;    

var questionsCount = ' [' + questions + ' questions left]';    

var adjective = prompt('Please type an adjective' + questionsCount);   

questions -= 1;   

questionsCount = ' [' + questions + ' questions left]';

var verb = prompt('Please type a verb' + questionsCount);

questions -= 1;

questionsCount = ' [' + questions + ' questions left]';

var noun = prompt('Please type a noun' + questionsCount);

alert('All done. Ready for the message?');

var sentence = "There once was a " + adjective;

sentence += ' programmer who wanted to use JavaScript to ' + verb;

sentence += ' the ' + noun + '.';

document.write(sentence);


偶然的你
浏览 138回答 1
1回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答