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")
相关推荐
恋猫de小郭5 分钟前
Flutter Widget IDE 预览新进展,开始推进落地发布
android·前端·flutter
jingling5551 小时前
【Vue3 实战】插槽封装与懒加载
前端·javascript·vue.js
Freedom风间6 小时前
前端优秀编码技巧
前端·javascript·代码规范
萌萌哒草头将军7 小时前
🚀🚀🚀 Openapi:全栈开发神器,0代码写后端!
前端·javascript·next.js
萌萌哒草头将军7 小时前
🚀🚀🚀 Prisma 爱之初体验:一款非常棒的 ORM 工具库
前端·javascript·orm
拉不动的猪7 小时前
SDK与API简单对比
前端·javascript·面试
runnerdancer7 小时前
微信小程序蓝牙通信开发之分包传输通信协议开发
前端
BillKu7 小时前
Vue3后代组件多祖先通讯设计方案
开发语言·javascript·ecmascript
山海上的风7 小时前
Vue里面elementUi-aside 和el-main不垂直排列
前端·vue.js·elementui