Jump to content
Sign in to follow this  
Ilias

Rock Paper Scissors

Recommended Posts

Hello,

 

In this tutorial I just wanna paste a very simple script for Rock, Paper, Scissors 

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
    computerChoice = "rock";
} else if(computerChoice <= 0.67) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";
}

console.log(computerChoice);

var compare = function(choice1, choice2) {
    if (choice1 === choice2) {
        return "The result is a tie!";
    }
    else if (choice1 === "rock") {
        if (choice2 === "scissors") {
            return "rock wins";
        }
        else {
            return "paper wins";
        }
    }
    else if (choice1 === "paper") {
        if (choice2 === "rock") {
            return "paper wins";
        }
        else {
            return "scissors wins";
        }
    }
    else if (choice1 === "scissors") {
        if (choice2 === "rock") {
            return "rock wins";
        }
        else {
            return "scissors wins";
        }
    }
};

compare(userChoice, computerChoice);

Any questions? you can put them in the reply I will try to answer on it 

Share this post


Link to post
Share on other sites

Hello,

 

In this tutorial I just wanna paste a very simple script for Rock, Paper, Scissors 

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
    computerChoice = "rock";
} else if(computerChoice <= 0.67) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";
}

console.log(computerChoice);

var compare = function(choice1, choice2) {
    if (choice1 === choice2) {
        return "The result is a tie!";
    }
    else if (choice1 === "rock") {
        if (choice2 === "scissors") {
            return "rock wins";
        }
        else {
            return "paper wins";
        }
    }
    else if (choice1 === "paper") {
        if (choice2 === "rock") {
            return "paper wins";
        }
        else {
            return "scissors wins";
        }
    }
    else if (choice1 === "scissors") {
        if (choice2 === "rock") {
            return "rock wins";
        }
        else {
            return "scissors wins";
        }
    }
};

compare(userChoice, computerChoice);

Any questions? you can put them in the reply I will try to answer on it 

 

I made a script "NPC" for this game it was funny xD

Share this post


Link to post
Share on other sites

This isn't java

this isn't even remotely related to java

java is not javascript

javascript is not a derivative of java

 

They are not even a little bit the same...

 

This section is for both natives.

Share this post


Link to post
Share on other sites

but why? they aren't even slightly simliar... the only thing they have in common is that they both have java in the name.

 

That is very inaccurate to the most degree.. Java is a programming language while JavaScript is a scripting language for java. /retard

Share this post


Link to post
Share on other sites

That is very inaccurate to the most degree.. Java is a programming language while JavaScript is a scripting language for java. /retard

no, javascript is a scripting language for web although in this case it looks like NodeJS which is javascript running on the V8 engine so it can be used as server side code but still, not even a little bit related to java...

Share this post


Link to post
Share on other sites

no, javascript is a scripting language for web although in this case it looks like NodeJS which is javascript running on the V8 engine so it can be used as server side code but still, not even a little bit related to java...

It doesn't matter. This subsection is for both Java and JavaScript. Cease the pointless argument and take it to PM. If you fail to do so, I'll be forced to take action.

 

 

Stay on topic. That includes you, Death, Epicblood, and Ultarg.

Share this post


Link to post
Share on other sites

It doesn't matter. This subsection is for both Java and JavaScript. Cease the pointless argument and take it to PM. If you fail to do so, I'll be forced to take action.

 

 

Stay on topic. That includes you, Death, Epicblood, and Ultarg.

:( please do not ban Death, he is cool

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

About us

MMO-Society is the Forum former known as Lordcraft, MMO-Society offers various of Resources to help you evolve your knowledge within Emulation, In the process we make sure to form a strong community bond in-between each other and thus we are proud to can admit that MMO-Society is possibly the friendliest Community Forum to currently exist.

Useful Quick-Links

×
×
  • Create New...