Tell us what’s happening:
My code outputs the correct strings, but code camp isn’t allowing me to move on. What do I need to fix and why?
Your code so far
reverseString(str).split("").reverse("").join("");
function reverseString(str) {
return str;
}
//end code
Your code contains global variables that are changed each time the function is run. This means that after each test completes, subsequent tests start with the new value. To fix this, make sure your function doesn’t change any global variables, and declare/assign variables within the function if they need to be changed.
Example:
var myGlobal = [1];
function returnGlobal(arg) {
myGlobal.push(arg);
return myGlobal;
} // unreliable - array gets longer each time the function is run
function returnLocal(arg) {
var myLocal = [1];
myLocal.push(arg);
return myLocal;
} // reliable - always returns an array of length 2
1 Like