I can't do Math.random well.

Asked 1 years ago, Updated 1 years ago, 36 views

I tried to generate a random number using Math.random, but when I looked at the console, the following error occurred and I couldn't.What is the cause?
Thank you for your cooperation.

error message

Uncaught TypeError: Math.ramdom is not a function
[email protected] ml:15
[email protected] ml:9

source code

<script>
  function getOmikuji(){
    varomikuji=["Okichi", "Nakayoshi", "Koyoshi";
    // a-n
    // Math.floor(Math.ramdom()*(n+1))
    var result=Math.floor(Math.ramdom()*3);

    alert(omikuji [result]);
  }
</script>

javascript

2022-09-30 20:48

1 Answers

Math.ramdom is spelled incorrectly. Try modifying it to Math.random.

This post was posted as a community wiki based on @BLUEPIXY's comments.


2022-09-30 20:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.