Repository navigation
#016 Basic Variable Assignment
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 called result.
He needs your help to fix this code.
Current source and tests | Catalog | Testing and tooling
From the cloned repository root, after installing dependencies:
node "Edabit/016 Basic Variable Assignment.js"Assertions are kept alongside the implementation and throw on failure. A successful run exits with code 0. Run every exercise with npm test or both lint and tests with npm run check.
This is the complete executable file, including its imports and inline test cases. Run it from the repository, not as an isolated file copied out of the wiki. Line endings and trailing whitespace are normalized; executable tokens are unchanged.
//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 called result.
//He needs your help to fix this code.
function nameString(name) {
const b = "Edabit";
const result = name + b;
return result;
}
import * as Test from '../testHelper.js';
Test.assertEquals(nameString("Mubashir"), "MubashirEdabit")
Test.assertEquals(nameString("Matt"), "MattEdabit")
Test.assertEquals(nameString("javaScript"), "javaScriptEdabit")
Test.assertEquals(nameString("Airforce"), "AirforceEdabit")