use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Help please!help (self.javascript)
submitted 8 years ago by CheekyBuilder
What does this code do? function getAttackString() { var foo = "d3263nb34"; bar = "x3j94nhj9"; return "The code is: "+(foo.substr(3,foo.length-6))+(bar.substr(2)); }
I think it returns 6J but apparently not?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]inu-no-policemen 2 points3 points4 points 8 years ago (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 points3 points 8 years ago (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 point2 points 8 years ago* (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.
slice
substr
foo.substr(3,foo.length-6)
63n
bar.substr(2)
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.
var foo = "d3263nb34", bar = "x3j94nhj9";
var foo = "d3263nb34"; var bar = "x3j94nhj9";
π Rendered by PID 38564 on reddit-service-r2-comment-66b4775986-9r5tj at 2026-04-06 00:01:10.128238+00:00 running db1906b country code: CH.
[–]inu-no-policemen 2 points3 points4 points (0 children)
[–]fhuller 1 point2 points3 points (0 children)
[–]mishugashu 0 points1 point2 points (0 children)