0037【Edabit ★☆☆☆☆☆】【修改Bug 2】Buggy Code (Part 2)

0037【Edabit ★☆☆☆☆☆】【修改Bug 2】Buggy Code (Part 2)

bugs language_fundamentals

Instructions

Fix the code in the code tab to pass this challenge (only syntax errors). Look at the examples below to get an idea of what the function should do.

Examples
javascript 复制代码
maxNum(3, 7) // 7
maxNum(-1, 0) // 0
maxNum(1000, 400) // 1000
Notes
  • READ EVERY WORD CAREFULLY, CHARACTER BY CHARACTER!
  • Don't overthink this challenge; it's not supposed to be hard.
Solutions
javascript 复制代码
// bugs
function maxNum(n1;n2) { // here,between paramters using `,` instead of `;`
	if (n1>n2) {
	  return n2 // here , we should return max number,n1
	}
  else if { // and here,remove `if`
	return n1
  }
}
// correct it !!
function maxNum(n1,n2) {
    if (n1>n2) {
        return n1
    } else  {
        return n1
    }
}
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);
            }
        }
    }
})();

Test.assertEquals(maxNum(3, 7), 7)
Test.assertEquals(maxNum(-1, 0), 0)
Test.assertEquals(maxNum(1000, 400), 1000)
Test.assertEquals(maxNum(-3, -9), -3)
Test.assertEquals(maxNum(88, 90), 90)
相关推荐
mCell2 小时前
使用 useSearchParams 同步 URL 和查询参数
前端·javascript·react.js
mCell3 小时前
前端路由详解:Hash vs History
前端·javascript·vue-router
海上彼尚3 小时前
无需绑卡的海外地图
前端·javascript·vue.js·node.js
1024肥宅4 小时前
手写 call、apply、bind 的实现
前端·javascript·ecmascript 6
xlq223224 小时前
22.多态(上)
开发语言·c++·算法
666HZ6664 小时前
C语言——高精度加法
c语言·开发语言·算法
科杰智能制造4 小时前
纯前端html、js实现人脸检测和表情检测,可直接在浏览器使用
前端·javascript·html
星释4 小时前
Rust 练习册 100:音乐音阶生成器
开发语言·后端·rust
每天吃饭的羊5 小时前
组件库的有些点击事件是name-click这是如何分装de
前端·javascript·vue.js
x***01065 小时前
SpringSecurity+jwt实现权限认证功能
android·前端·后端