0049【Edabit ★☆☆☆☆☆】【修改Bug代码】Buggy Code
bugs
language_fundamentals
Instructions
The challenge is to try and fix this buggy code, given the inputs
true
andfalse
. See the examples below for the expected output.
Examples
javascript
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
javascript
// 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
javascript
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")