What is the output of this function?


#1

If there is an error can you please solve it then tell me the correct output!
Thanks,

function getAttackString() {
var foo = “d323b8b34”;
var bar = “x334q3j98”;
return "The code is: "+(foo.substr(3,foo.length-6))+(bar.substr(2));
}


#2

To know the output call the function at the end

console.log(getAttackString()) //calling the function


#3

The substr() function will extract a ‘piece’ of your string, and it gets two arguments: start and length, right?
The start one is obligatory and determines were you wanna begin your extraction. The length is not obligatory but put the limit of characters of your piece (if you don’t use it, it will extract until the end of the original string).

(foo.substr(3,foo.length-6)) returns "3b8" and (bar.substr(2)) returns "34q3j98"

Therefore, getAttackString() will return: The code is: 3b834q3j98

If I’m committing a mistake, please let me know.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.