npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rockpaperscissorsjs

v1.1.5

Published

ready made package to help you with your rock paper scissors project.

Downloads

18

Readme

RockPaperScissorsJS


moved to RPSjs

Table of content

intro


  const player = new Play('paper'); 
  //this creates a new object player and the action must be passed as an argument
  //the three actions are users guess which could be `rock`,`paper` or `scissors`

 console.log(player.Roll()); 
 //the Roll() function assigned is where everything is done mostly.

the response or display on the console:

[
   user: 'paper',
   computer: 'scissors',
   won: true
]

in the above the user placed paper which we see from the argument passed on new play('paper') and the computers guess is randomly generated and from the result we get that paper loses to scissors and hence the result brings false meaning the user lost, incase of a win it would be true and incase of draw it would be draw.

getting started


getting started you will first require the library which can be done by using the script tags

   <script src="./path/to/rockPaperScissors.JS"> </script>// get the library from the path where it's located

or if you are using a CDN then you can use the following

   <script src="https://cdn.jsdelivr.net/npm/[email protected]/rockPaperScissors.min.js"></script> 

the import is still not fully functional

place the CDN link onto the header

then crate an object to use

    const player = new Play();// you can name it anything other than player

you can find the demos here

using the functions

there are three functions;

       Roll(user)//argument are not required 
       Compute()
       Won(user, computer)// required!

Note that the functions beggin with a capital letter.

Roll

from the above example you can see that the Roll() function did everything for us without us doing anything. the Roll() function requires no parameters if you stated it when making the Object. Example 1:

  const player = new Play('rock');// user guess in this case is rock
  console.log(player.Roll());// since user guess was passed on the object there is no need to redo that again

Example 2:

   const player = new Play();// user guess not passed
  console.log(player.Roll('paper'));
    [
       user: rock,
       computer: scissors,
       won: true
    ]

Example 2 output could be:

    [
       user: paper,
       computer: paper,
       won: draw
    ]

the computer guess is randomly made

Compute


the compute() function will help you if you would like to get a random guess for the computer; Example:

const player = new Play();
let button = document.getElementById('computer-guess');
button.addEventListener('click', function(){
    console.log('The computer guess is: '+player.Compute());
})

Example of output: The computer guess is: rock

you can do a lot more with this just check the examples here

won

       Won(user, computer)          

This function determines the winner where the data passed required arguments are user and computer guess or trows eg. rock or paper or scissors

it will to be like

      player.Won('rock','scissors')// user= rock and computer=scissors
      player.Won('paper','paper')// user= paper and computer=paper
      player.Won('scissors','rock')// user=scissors  and computer=rock

Example:

     const player = new Play();

        console.log(player.Won('rock','scissors'))// user= rock and computer=scissors
        console.log(player.Won('scissors','scissors'))// user= scissors and computer=scissors
        console.log(player.Won('scissors','rock'))// user=scissors  and computer=rock 

output:

       true
       draw
       false

passing numbers is still supported but not required

extra


this are just some extras

  • you can clone this on github and if you would like to Contribute you can send a pull request and I will check it out and see if I can marge it.
  • creator bethropolis;

License


Licensed under my favourate License, MIT License.