.innerHTML not updating HTML in Javascript -
Working on a rock paper scissor assignment, where the increase of a global variable increases, depending on whether the computer or Humans live. My work works fine, but the scoreboard will not be updated while using. WinnerHTML Any suggestions?
document.getElementById ("humanScore"). InnerHTML = humanTotal; Document.getElementById ("computerScore"). Internal html = complex;
You have some problems.
In your play function, you are not doing anything with the computerChoice variable, and this function should be on the call compPlay () . Currently it is var computerChoice = compPlay , which is actually assigning computerChoice to a function, not the result of it. If the statement in the second test, you are again examining compPlay , which is a function, I think it is the computerChoice must be the third one. Return value from compPlay is an index, it will be updated from compOptions array code
diverse human total = 0 ; Var compatible = 0; Document.getElementById ("rock"). Onclick = setRock; Document.getElementById ("Paper"). Onclick = setPaper; Document.getElementById ("Scissors"). Onclick = setScissors; Function setper () (play ("rock")} function set popper () {play ("paper")} function set; secrecy () {play ("scissors")} function play (human Choice) {var computerChoice = compPlay (); // Change here // if all to check the computer option if the statement (Human Choice == "Rock") {if (Computer Charge == "Rock") {} and if (Computer Charge = = "Scissors") {Human Total ++;} And if (Computer Charge == "Paper") {compTotal ++;}} If (humanChoice == "Paper") {If (computerChoice == "Paper") { } Else if (computerChoice == "rock") {human total ++;} and if (computer charge == "scissors") {compTotal ++;}} If (humanChoice == "scissors") {if (computerChoice == "scissors") {} else if (computerChoice == "papers") {human total ++; } And if (computer charge == "rock") {compTotal ++;}} document.getElementById ("humanScore") .internalHTML = humancode; Document.getElementById ("computerScore") .internal HTML = Complement;} function ) {Var compOptions = ['rock', 'paper', 'scissor']; var randomChoice = Math.floor (Math.random (* * compOptions.length)); Return compaction [random options]; // & lt; - Change here} There is nothing with internal HTML, which is working fine, it was just that the score is always zero. The reason for this was that if any of the statements being made for "rock", "paper" or "scissors" did not prove to be true as a computer, chewing "rock", "paper" or "scissors" Did not match, but this is your function.
Comments
Post a Comment