【Edabit 算法 ★☆☆☆☆☆】 Basic Variable Assignment
bugs
functional_programming
language_fundametals
strings
Instructions
A student learning JavaScript was trying to make a function. His code should concatenate a passed string
name
with string"Edabit"
and store it in a variable calledresult
. He needs your help to fix this code.
Examples
nameString("Mubashir") // "MubashirEdabit"
nameString("Matt") // "MattEdabit"
nameString("javaScript") // "javaScriptEdabit"
Notes
- Don’t forget to return the result.
Solutions
function nameString(name){var b = "Edabit" // '==' 改为 '='var result = name + b // '==' 改为 '='return result
}
TestCases
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(nameString("Mubashir"), "MubashirEdabit")
Test.assertEquals(nameString("Matt"), "MattEdabit")
Test.assertEquals(nameString("javaScript"), "javaScriptEdabit")
Test.assertEquals(nameString("Airforce"), "AirforceEdabit")