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")
相关推荐
java1234_小锋10 小时前
【技术专题】HTML5 网页技术 - HTML5简介 & HTML5 文档结构
前端·html·html5
鶴哥只手遮天11 小时前
Vue 3 核心源码深度剖析系列(v3.5.44)-第 1 章 项目全景:monorepo 架构与工程化体系
前端·vue.js·开源
流星。。方11 小时前
小团队官网SEO落地:前端语义化与静态生成的工程实践
前端·状态模式
用户5304297657911 小时前
盘点危化品搬运诊断的6类工具与自处理边界判断
前端
curtain11 小时前
从古法编程到 Agent:我入行这两年,AI 改变了什么
前端·openai
zyfts11 小时前
10分钟自制Codex钉钉通知Skill:AI干完活自动钉钉提醒你
前端
大孜然11 小时前
孜然QQ频道自动化程序机器人配置教程
前端
用户4693849215511 小时前
AIUI 焦点高亮切换失效排查与规避:为什么按钮不变换形态呢?
前端
派大鑫wink11 小时前
纯前端实现软考中级·软件设计师备考学习网站
前端·学习
kyriewen11 小时前
我扒了 npm 三年数据:AI 没把依赖变胖,是把包变多了
前端·人工智能·程序员