Skip to content

Math.random code will only shuffle answer into first three containers #7

@agarbiak

Description

@agarbiak

This was a really great tutorial series - easy to follow and quick to build!

I think I have found a small issue with the following code:

formattedQuestion.answer = Math.floor(Math.random() * 3) + 1;

Math.random() returns a value in the range [0,1), i.e. it will never return 1 - see source.

So it looks like the code will only return values of 1, 2 or 3. Never 4.

I think a simple fix is the following:
formattedQuestion.answer = Math.floor(Math.random() * 4) + 1;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy