本文主要是介绍【Edabit 算法 ★☆☆☆☆☆】 Basic Variable Assignment,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
【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")
这篇关于【Edabit 算法 ★☆☆☆☆☆】 Basic Variable Assignment的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!