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
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")
相关推荐
雪芽蓝域zzs7 小时前
第二十二节:进阶:用户管理新增、编辑弹窗 + 表单校验
前端·javascript·vue.js
IT_陈寒7 小时前
Java字符串判等踩坑记:==和equals真的不能乱用
前端·人工智能·后端
shmily麻瓜小菜鸡7 小时前
JavaScript / TypeScript 易踩坑知识点 —— 作用域与变量类
开发语言·javascript·typescript
晴天167 小时前
前端虚拟滚动(虚拟列表)原理与实战
前端
晴天168 小时前
前端 RAIL 性能模型实战分享-Day37
前端
变与不变8068 小时前
JS作用域,作用域链
前端·javascript·es6
知兀8 小时前
Tailwindcss报错:没有与此调用匹配的重载
前端·c++·tailwindcss
晴天168 小时前
Chrome WebMCP 让网站学会向 AI「自我介绍」
前端·人工智能·chrome
雪芽蓝域zzs8 小时前
二十一节:进阶:用户列表批量删除功能
前端·javascript·vue.js
研☆香8 小时前
可选链运算符和空值合并运算符的使用
前端·javascript·vue.js