0

have an issue

can someone explain me? function win() { userScore++; userScore_span.innerHTML = userScore; compScore_span.innerHTML = compScore; in console it tells me its an error: app.js:21 Uncaught TypeError: Cannot set property 'innerHTML' of null please !

1st Aug 2020, 9:18 PM
GhostRecon
GhostRecon - avatar
5 odpowiedzi
+ 2
You need to assign an element to the variable userScore_span before using the innerHTML property. For example: var userScore_span = document.getElementsByTagName("span")[0];
1st Aug 2020, 10:27 PM
Javier Ballesteros
Javier Ballesteros - avatar
0
Try this window.onload = function(){ -- js code -- }
1st Aug 2020, 9:31 PM
Divya Mohan
Divya Mohan - avatar
0
its not working :( ..tells me : Uncaught SyntaxError: Unexpected identifier
1st Aug 2020, 9:42 PM
GhostRecon
GhostRecon - avatar
0
as Divya Mohan mentioned try that method or link your code in description ,ty
1st Aug 2020, 10:05 PM
Abhay
Abhay - avatar
0
let userScore = 0; let compScore = 0; const userScore_span = document.getElementById("user-score"); const compScore_span = document.getElementById("comp-score"); const scoreBoard_div = document.querySelector(".score-board"); const result_div = document.querySelector(".result"); const rock_div = document.getElementById("r"); const paper_div = document.getElementById("p"); const scissors_div = document.getElementById("s"); function getcompChoice() { const choices = ['r', 'p', 's']; const randomNumber = Math.floor(Math.random() * 3); return choices[randomNumber]; } function win() { userScore++; document.getElementById("userScore_span").innerHTML= userScore; document.getElementById("compScpre_span").innerHTML= compScore; console.log(user); console.log(comp); } function lose() { console.log("LOST"); } function draw() { console.log("DRAW"); } function game(userChoice) { const compChoice = getcompChoice(); switch (userChoice + compChoice) { case "rs": case "pr": case "sp": win(); break; case "rp": case "ps": case "sr": lose(userChoice, compChoice); break; case "rr": case "pp": case "ss": draw(userChoice, compChoice); break; } } function main() { rock_div.addEventListener('click', function() { game("r"); }) paper_div.addEventListener('click', function() { game("p"); }) scissors_div.addEventListener('click', function() { game("s"); }) } main()
1st Aug 2020, 10:13 PM
GhostRecon
GhostRecon - avatar