0049【Edabit ★☆☆☆☆☆】【修改Bug代码】Buggy Code
bugs
language_fundamentals
文章来源:https://www.toymoban.com/news/detail-733707.html
Instructions
The challenge is to try and fix this buggy code, given the inputs
true
andfalse
. See the examples below for the expected output.文章来源地址https://www.toymoban.com/news/detail-733707.html
Examples
has_bugs(true) // "sad days"
has_bugs(false) // "it's a good day"
Notes
- Don’t overthink this challenge (look at the syntax and correct it).
Solutions
// bugs
function has_bugs(buggy_code) {
if (buggyCode) {
return 'sad days'
} else if { // here ,remove `if`
return 'it's a good day' // here escape \'
}
}
// correct it !!
function has_bugs(buggy_code) {
if (buggyCode) {
return 'sad days'
} else {
return 'it\'s a good day'
}
}
TestCases
let Test = (function(){
return {
assertEquals:function(actual,expected){
if(actual !== expected){
let errorMsg = `actual is ${actual},${expected} is expected`;
throw new Error(errorMsg);
}
},
assertSimilar:function(actual,expected){
if(actual.length != expected.length){
throw new Error(`length is not equals, ${actual},${expected}`);
}
for(let a of actual){
if(!expected.includes(a)){
throw new Error(`missing ${a}`);
}
}
}
}
})();
Test.assertEquals(has_bugs(true), "sad days")
Test.assertEquals(has_bugs(false), "it's a good day")
到了这里,关于0049【Edabit ★☆☆☆☆☆】【修改Bug代码】Buggy Code的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!