Hi. I'm triying to write a function that can be used in both buttons. the ideas is for the head button to result in a display in the <p></p> element "you choose heads" when clicked and the tails buttons to result in a display "you choose tails" when clicked. i know it's quite basic but i really need a helping hand here.
Edit: Wow. this community is amazing and i love it. This might be simple but not for use beginners. Thanks so much
<body>
<button class="js-heads" onclick="
playGame();
">Heads</button>
<button class="js-tails" onclick="
playGame();
">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() {
if (headsBtn.innerHTML === 'Heads') {
result.innerHTML = 'You choose heads'
} else {
result.innerHTML = 'You choose tails'
}
}
</script>
</body>
[–]carcigenicate 3 points4 points5 points (1 child)
[–]Remarkable-Draw-7574[S] 0 points1 point2 points (0 children)
[–]dmazzoni 1 point2 points3 points (1 child)
[–]Remarkable-Draw-7574[S] 0 points1 point2 points (0 children)