本文主要是介绍0049【Edabit ★☆☆☆☆☆】【修改Bug代码】Buggy Code,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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
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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!