Random Value Generation
It is important to define a function that will generate some values when called and this should not be some predefined values. That is why we need to generate some unpredictable and random values from our functions.
There is a function Math.random(), which is used to return a floating-point pseudo-random number.
It ranges [0,1) , 0 (inclusive) and 1 (exclusive). According to the desired range, these random numbers can be scaled.
After declaring Math.random (), assign the values as Stone, Paper, and Scissor on the basis of the ranges.
If the value is less than 0.3 it will return Scissors if between 0.3 to 0.6 then returns Paper otherwise will return Stone
The function to generate random values and assigning them Stone, Paper, and Scissor on the basis of their range.
Comparing Given Input vs Returned Value
Define a function that will compare the returned value, which was generated due to Math.random ( ) and the values which will be provided by the user.
Conditional rendering is needed for this function.
The conditions will be: If the values are the same then it is a draw otherwise, provide necessary conditions to display whether it is a win or a loose.
For example :
If the user input value is Scissors and randomly generated value is not stone then the user wins or else it is loose.
The function to compare the values a deciding whether it is loose or win.
Calling the Function and Printing it
After defining all the functions, just simply call them and print them using console.log(function_name("Parameter")).
NOTE: These are case sensitive and should be between inverted commas.
The part /*your words*/ should contain Stone paper or Scissor only.
For full code and assistance visit the repository.