This is not working out, i'm not too sure how I can add whitespace to
both ends of a string.
you're always resetting the parameter str
to empty string hence the unexpected behaviour.
there are two ways you could solve the issue at hand.
1) you could use console.log()
inside the method, example:
function space(str, numSpace) {
var result = numSpace + str + numSpace;
console.log(result);
}
space("hi", " ");
2) you could return the value then use console.log()
:
function space(str, numSpace) {
return numSpace + str + numSpace;
}
var result = space("hi", " ");
console.log(result);