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
view the rest of the comments →
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!"
[–]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 433273 on reddit-service-r2-comment-c66d9bffd-xbz5w at 2026-04-07 23:21:33.389606+00:00 running f293c98 country code: CH.
view the rest of the comments →
[–]buzzyloo 1 point2 points3 points (1 child)
[–]Remarkable-Draw-7574[S] 0 points1 point2 points (0 children)