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 and false. 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")

你可能感兴趣的:(#,Edabit,bug,前端,javascript)