【发布时间】:2018-05-30 20:40:24
【问题描述】:
我对 javascript 还是很陌生,所以如果这很烦人,我深表歉意。所以我有一个我不熟悉并试图解决的非常奇怪的问题。我要完成下面列出的“爬升”功能。我需要在函数爬升中使用内置的局部变量参数。我不能改变函数来接受参数,这个练习的目的是在函数范围内使用局部参数变量。任何帮助是极大的赞赏!提前致谢。
这是函数必须做的:
If there is a string at arguments[0] but arguments[1] is falsy, return "On belay?".
If there is a string at arguments[0], and true at arguments[1],
return "Climbing!"
Otherwise, return "Let's set up the belay rope before we climb."
它还必须通过所有这些测试:
should be a function that does not have built-in parameters
should return "Let's set up the belay rope before we climb." if called as climb()
should return "Climbing!" if called with climb("Benny", true)
should return "Climbing!" if called with climb("any string here", true)
should return "On belay?" if called with climb("Benny", false)
should return "On belay?" if called with climb("any string here")
这是我提供的功能的开始:
function climb(){
//CODE HERE - DO NOT TOUCH THE CODE ABOVE!
}
这是我正在尝试的:
function climb(){
//CODE HERE - DO NOT TOUCH THE CODE ABOVE!
if(arguments[0]){
if(arguments[1]==false){
return "On belay?";
} else {
return "Climbing!";
}
} else {
return "Let's set up the belay rope before we climb.";
}
}
这通过了除此之外的所有测试:
should return "On belay?" if called with climb("any string here")
【问题讨论】:
-
关键是你如何检查“假”值。
标签: javascript arguments