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")
相关推荐
天若有情67315 分钟前
【c++】手撸C++ Promise:从零实现通用异步回调组件,支持链式调用+异常安全
开发语言·前端·javascript·c++·promise
抱琴_34 分钟前
【Vue3】大屏性能优化黑科技:Vue 3 中实现请求合并,让你的大屏飞起来!
前端·vue.js
不会玩电脑的Xin.36 分钟前
HTML + CSS
前端·css·html
hadage2331 小时前
--- JavaScript 的一些常用语法总结 ---
java·前端·javascript
彭于晏爱编程1 小时前
🍭🍭🍭升级 AntD 6:做第一个吃螃蟹的人
前端
掘金一周1 小时前
大部分人都错了!这才是chrome插件多脚本通信的正确姿势 | 掘金一周 11.27
前端·人工智能·后端
jason_yang2 小时前
vue3中createApp多个实例共享状态
javascript·vue.js
_瑶瑶_2 小时前
浅记一下ElementPlus中的虚拟化表格(el-table-v2)的简单使用
前端·javascript
Drift_Dream2 小时前
ResizeObserver:轻松监听元素尺寸变化
前端