0037【Edabit ★☆☆☆☆☆】【修改Bug 2】Buggy Code (Part 2)
bugs
language_fundamentals
文章来源:https://www.toymoban.com/news/detail-723121.html
Instructions
Fix the code in the code tab to pass this challenge (only syntax errors). Look at the examples below to get an idea of what the function should do.文章来源地址https://www.toymoban.com/news/detail-723121.html
Examples
maxNum(3, 7) // 7
maxNum(-1, 0) // 0
maxNum(1000, 400) // 1000
Notes
- READ EVERY WORD CAREFULLY, CHARACTER BY CHARACTER!
- Don’t overthink this challenge; it’s not supposed to be hard.
Solutions
// bugs
function maxNum(n1;n2) { // here,between paramters using `,` instead of `;`
if (n1>n2) {
return n2 // here , we should return max number,n1
}
else if { // and here,remove `if`
return n1
}
}
// correct it !!
function maxNum(n1,n2) {
if (n1>n2) {
return n1
} else {
return n1
}
}
TestCases
let Test = (function(){
return {
assertEquals:function(actual,expected){
if(actual !== expected){
let errorMsg = `actual is ${actual},${expected} is expected`;
throw new Error(errorMsg);
}
}
}
})();
Test.assertEquals(maxNum(3, 7), 7)
Test.assertEquals(maxNum(-1, 0), 0)
Test.assertEquals(maxNum(1000, 400), 1000)
Test.assertEquals(maxNum(-3, -9), -3)
Test.assertEquals(maxNum(88, 90), 90)
到了这里,关于0037【Edabit ★☆☆☆☆☆】【修改Bug 2】Buggy Code (Part 2)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!