Rock paper scissors problem


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/1/4?curriculum_id=506324b3a7dffd00020bf661


This is the code for the game but it is not working in browser.Browser does not show any thing after i select one choice of user.


<html>
<script>
var userChoice=prompt("Do you choose rock,paper or scissors");
var computerChoice=Math.random();
if(computerChoice<=0.33){
 computerChoice="rock";
}
else if(computerChoice<=0.66){
 computerChoice="paper";
}
else{
 computerChoice="scissors";
}
console.log("Computeer "+computerChoice);
var compare=function(userChoice, computerChoice){
 if (userChoice==computerChoice){
 return "Result is a tie!";
 }
 else if(userChoice=="rock"){
 if(ComputerChoice=="scissors"){
 return "rock wins";
 }
 else{
 return "paper wins";
 }
 }
 else if(userChoice=="paper"){
 if(computerChpoice=="rock"){
 return "paper wins";
 }
 else{
 retun "scissors wins";
 }
 }
 else{
 if(computerChoice=="rock"){
 return "rock wins";
 }
 else{
 return "scissors wins";
 }
 }
}
compare(userChoice, computerChoice);
</script>
</html>


#2

What's supposed to happen instead? Have you written any code that in any way is meant to interact with the user after having made that choice?


#3

it is the final code as you know in rock paper excercise i have completed that exercise and code works well there but when i try to use that code to run in browser it does not show any thing that who wins


#4

The point I'm trying to make is that if you don't write code to do a particular something, then that particular something probably won't happen.

So, when you say work, what do you mean? That something is printed? Shown in an alert? Do you have code that makes that happen? If not, then it won't.


#5

i have use console.log to display the winner but browser does not show any thing


#6

Do you though? There is one call to console.log. What does it display? It's not the winner.

You're not printing it, therefore it's not showing. Simple as that. Also make sure that you're looking at the console since that's where you would be printing, you are not displaying it on the page itself.


#7

then how can i display that console message on web page?


#8

The console and the web page are two separate things.
You'll have to ask yourself where it's supposed to show up. In the console, as an alert, or on the page itself.

You could use this function to add some text to the page:

function presentResult(message) {
  var newHeader = document.createElement('h1');
  newHeader.innerHTML = message;
  document.body.appendChild(newHeader);
}

#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.