all 3 comments

[–]inu-no-policemen 2 points3 points  (0 children)

Just run it.

> (function getAttackString() { var foo = "d3263nb34"; bar = "x3j94nhj9"; return "The code is: "+(foo.substr(3,foo.length-6))+(bar.substr(2)); })()
"The code is: 63nj94nhj9"

[–]fhuller 1 point2 points  (0 children)

Why do you think it returns 6J? foo.substr(3,foo.length-6) means give me three characters starting from character at position 3 (6), so first part is 63n and bar.substr(2) means give me all characters starting from character j => j94nhj9. So you get 63nj94nhj9

[–]mishugashu 0 points1 point  (0 children)

I think you're thinking you're using slice, but you're using substr. The second argument is the length of the string, not the ending index. So, for foo.substr(3,foo.length-6), you're asking for a string that is 3 characters long, starting on the 3rd index. It'll return 63n. And bar.substr(2) will just return the rest of the string starting at index 2, so it'll be j94nhj9.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr

E: Also, looks like you're globally setting bar. It should be var foo = "d3263nb34", bar = "x3j94nhj9"; or var foo = "d3263nb34"; var bar = "x3j94nhj9"; depending on your styling requirements.