JS中if /else if 的问题
题目要求:1:Writeanif/elsestatementinsidetheisEvenfunction.Itshouldreturntrue;ifthenumberi...
题目要求:1:Write an if / else statement inside the isEven function. It should return true; if the number it receives is evenly divisible by 2. Otherwise (else), it shouldreturn false;.
Make sure to return - don't useconsole.log()!
2:Add an else if branch to your existing if/else statement. If thenumber put into the function is not a number at all, instead of returntrue; or return false;, the function should return a string that tells the user that their input isn't a number. (This string can say whatever you like.)
--------------------------------------------------------------------代码------------------------
var isEven = function(number) {
if(!isNaN(number)){
return "ok,go on"}
else if(number % 2 ==0){
return true ;}
else{
return "please input a number"
return false;}
}
————————————————————————————————————————
系统提示我说: Your function returns true for 3!
怎么弄呢?
!!! 展开
Make sure to return - don't useconsole.log()!
2:Add an else if branch to your existing if/else statement. If thenumber put into the function is not a number at all, instead of returntrue; or return false;, the function should return a string that tells the user that their input isn't a number. (This string can say whatever you like.)
--------------------------------------------------------------------代码------------------------
var isEven = function(number) {
if(!isNaN(number)){
return "ok,go on"}
else if(number % 2 ==0){
return true ;}
else{
return "please input a number"
return false;}
}
————————————————————————————————————————
系统提示我说: Your function returns true for 3!
怎么弄呢?
!!! 展开
3个回答
展开全部
为什么下面的else里有两个return
追问
那正确的代码是怎样阿
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
执行到第一return后就不往后执行了
追问
那么,正确的做法是?
那么,正确的做法是?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
删掉一个return
更多追问追答
追问
😚请问哪个
追答
看你需要了
return "please input a number"
return false;
任选一个
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询