Skip to content

Commit

Permalink
fix typo on Web/JavaScript (mdn#3773)
Browse files Browse the repository at this point in the history
- Taken the list item content to it's intended list item to prevent confusion
- Added a "brush: js" class to a <pre> tag for "Math.floor(Math.random()) + 1" content in the "working through the logic" section of the article.
  • Loading branch information
AlvinMrema authored Apr 3, 2021
1 parent e4956d3 commit 33aaca1
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,9 @@ <h2 id="A_logic_error">A logic error</h2>

<ol>
<li>Search for the <code>randomNumber</code> variable, and the lines where the random number is first set. The instance that stores the random number that we want to guess at the start of the game should be around line number 44:

<pre class="brush: js">let randomNumber = Math.floor(Math.random()) + 1;</pre>
And the one that generates the random number before each subsequent game is around line 113:</li>
<li>
</li>
<li>And the one that generates the random number before each subsequent game is around line 113:
<pre class="brush: js">randomNumber = Math.floor(Math.random()) + 1;</pre>
</li>
<li>To check whether these lines are indeed the problem, let's turn to our friend <code>console.log()</code> again — insert the following line directly below each of the above two lines:
Expand All @@ -156,7 +155,7 @@ <h3 id="Working_through_the_logic">Working through the logic</h3>

<p>Next, we pass the result of invoking <code>Math.random()</code> through <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor">Math.floor()</a></code>, which rounds the number passed to it down to the nearest whole number. We then add 1 to that result:</p>

<pre>Math.floor(Math.random()) + 1</pre>
<pre class="brush: js">Math.floor(Math.random()) + 1</pre>

<p>Rounding a random decimal number between 0 and 1 down will always return 0, so adding 1 to it will always return 1.  We need to multiply the random number by 100 before we round it down. The following would give us a random number between 0 and 99:</p>

Expand Down

0 comments on commit 33aaca1

Please sign in to comment.