My JS code won't working don't know where did i made mistake it seems all ok to me

My JS code won't working don't know where did i made mistake it seems all ok to me
0.0 0

#1

here is my JS Code
<------------------------------------------------->

$(document).ready(function(){
  function getQuote()
  {
    var quotes=["shani","baba","Me","I'm"];
    var authors=["A1","A2","A3"];
    var randomNum=math.floor((math.random()*quotes.length));
    var randomQuote=quotes[randomNum];
    var randomAuthor=authors[randomNum];
    $(".quote").text(randomQuote);
    $(".author").text(randomAuthor);
  }
    $(".mybutton").on("click",function(){
    
      getQuote();
    });
  
  
});

<------------------------------------------------>
Here is my HTML
<------------------------------------------------->

<div class="container text-center">
  <h1>Random Quote Generator</h1>
  </br>
  <button class="mybutton" type=submit> New Quote </button>
<div class="quotes">
  <span class="quote"> Hello World !! </span>
  <span class="author">The World</span>
</div>



</div>
<------------------------------------------------------>

Thanks in Advance


#2

There are some errors in your code. Here an working example of your refactored code. Take a closer look at the commas you are using:

var quotes=[“shani”,“baba”,“Me”,“I’m”];
var authors=[“A1”,“A2”,“A3”];

and this ones:

  var quotes = ["shani", "baba", "Me", "I’m"];
  var authors = ["A1", "A2", "A3"];

#3

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#4

First question for you: Are you getting any errors showing in the browser’s console (Ctrl+Shft+J in Chrome)? If so, see if you can fix those first.

One error I see right off is the following:

JavaScript is case-sensitive, so math is not the same as Math. Double check what case your built-in function calls should be.


#5

Got it. it was a case-sensitive error and a spell error i.e math.randon replaced with Math.random :slight_smile:
thank you for giving me your time.


#6

it wasn’t issue of commas it was mis spell and case-sensitive issue.


#7

You can get rid of your ‘type=submit’ from your button html too