需要大神用javascript 写一个代码。十万火急 javascript 高手进
需要大神用javascript写一个代码。十万火急//Challenge6//Thecodebelowpicksarandomnumberbetween1and10and...
需要大神用javascript 写一个代码。十万火急
//Challenge 6
//The code below picks a random number between 1 and 10 and stores it in the variable randomNumber. Prompt the user to enter a number. If the number is equal to the randomNumber, alert "Yes! The correct number is X" where X is the value of randomNumber. Otherwise, print out "Sorry, the correct number was X", where X is the value of randomNumber.
var randomNumber = Math.round(Math.random()*10)+1;
var guess = parseInt(prompt("Enter a number between 1 and 10"));
//Challenge 7
//Ask the user how many days it has been since playing basketball. If the response is less than 2, print 'You're a basketball enthusiast!' If the response is between 2 and 5, print 'You only sometimes play basketball'. If the response is more than 5, print 'You must not enjoy basketball at all.' 展开
//Challenge 6
//The code below picks a random number between 1 and 10 and stores it in the variable randomNumber. Prompt the user to enter a number. If the number is equal to the randomNumber, alert "Yes! The correct number is X" where X is the value of randomNumber. Otherwise, print out "Sorry, the correct number was X", where X is the value of randomNumber.
var randomNumber = Math.round(Math.random()*10)+1;
var guess = parseInt(prompt("Enter a number between 1 and 10"));
//Challenge 7
//Ask the user how many days it has been since playing basketball. If the response is less than 2, print 'You're a basketball enthusiast!' If the response is between 2 and 5, print 'You only sometimes play basketball'. If the response is more than 5, print 'You must not enjoy basketball at all.' 展开
1个回答
展开全部
if(guess === randomNumber) {
alert("Yes! The correct number is " + guess);
}
else {
alert("Sorry, the correct number was " + randomNumber);
}
var s1 = "You're a basketball enthusiast!",
s2 = 'You only sometimes play basketball',
s3 = 'You must not enjoy basketball at all.';
var guess = parseInt(prompt("How many days it has been since playing basketball?"));
if (guess < 2) alert(s1);
if (guess >= 2 && guess <= 5) alert(s2);
if (guess > 5) alert(s3);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询