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")
相关推荐
JustHappy6 分钟前
古法编程秘籍(七):互联网到底是什么?把两台电脑怎么说话搞懂就够了
前端·后端·网络协议
老毛肚9 分钟前
jeecg-boot-base-core 02 day
javascript·python
snow@li10 分钟前
SEO-文章标题:写文章时候,分类+主标题+大纲+解释 作为标题 / 不点进去也知道全文覆盖什么 / 标题即架构
前端
kyriewen1 小时前
Git Commit 前自动修复代码风格?配置 Husky + lint-staged,从此 CR 只聊逻辑
前端·git·面试
小和尚同志1 小时前
AI 自动化测试探索(一):Playwright MCP
前端·人工智能·aigc
老马识途2.02 小时前
在AI的帮助下理解spring的启动过程
java·前端·spring
徐小夕2 小时前
Loop Engineering 深度解析与实战指南(全网最全)
前端·算法·github
运筹vivo@2 小时前
Python ContextVar 底层机制与内存模型拆解
前端·数据库·python
#麻辣小龙虾#4 小时前
基于vue3.0开发一款【固废与废气运维管理系统】(支持源码)
前端·vue.js·vue3
Cosolar4 小时前
Docsify零构建文档站完全指南:从快速搭建到企业级部署
前端·开源·github