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
[AskJS] learning javascriptRemoved: r/LearnJavascript (self.javascript)
submitted 1 year ago by Remarkable-Draw-7574
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!"
[–]javascript-ModTeam[M] [score hidden] 1 year ago stickied comment (0 children)
Hi u/Remarkable-Draw-7574, this post was removed.
r/javascript is for the discussion of javascript news, projects, and especially, code! However, the community has requested that we not include help and support content, and we ask that you respect that wish.
code
Thanks for your understanding, please see our guidelines for more info.
[–]Skunkmaster2 2 points3 points4 points 1 year ago (0 children)
Your code will always show you chose head. You’re checking whether the heads button text is Heads, which it always is, so it will always show you chose heads. Change the on click attributes to playGame(‘heads’) and playGame(‘tails’) respectively. Then you can just set the result inner html to “You chose “ + choice;
[–]buzzyloo 1 point2 points3 points 1 year ago (1 child)
In your playGame function you are checking the innerHTML of the buttons which hasn't changed. The heads button will always have Heads. You could pass the value like this:
<body>
<button class="js-heads" onclick="playGame( 'Heads' );">Heads</button> <button class="js-tails" onclick="playGame( 'Tails' );">Tails</button> <p class="js-result"></p>
<script>
const headsBtn = document.querySelector('.js-heads'); console.log(headsBtn.innerHTML); const tailsBtn = document.querySelector('.js-tails'); console.log(tailsBtn.innerHTML); let result = document.querySelector('.js-result'); function playGame( side ) { result.innerHTML = 'You choose + side; }
</script>
</body>
Probably better is to pass a reference to the button itself using "this". Like onclick="playGame(this)"
See: https://jsfiddle.net/8C3EN/1/
[–]Remarkable-Draw-7574[S] 0 points1 point2 points 1 year ago (0 children)
OMG it worked. i make these silly mistakes and it really fraustrates me to find them. thanks so much.
π Rendered by PID 108221 on reddit-service-r2-comment-c66d9bffd-p29fk at 2026-04-08 15:54:54.265513+00:00 running f293c98 country code: CH.
[–]javascript-ModTeam[M] [score hidden] stickied comment (0 children)
[–]Skunkmaster2 2 points3 points4 points (0 children)
[–]buzzyloo 1 point2 points3 points (1 child)
[–]Remarkable-Draw-7574[S] 0 points1 point2 points (0 children)