Random quote machine popup help

Random quote machine popup help
0.0 0

#1

My main idea is that I want to use a random number that corresponds to a switch statement that has my quotes stored. I want the html to then show the quotes as a popup, then it lets you upload the quote to twitter. This is the most complex thing I have tried to code and I can’t even get the popup to work at all. Can anyone guide me and give me hints?


#2

Take a look at your browser’s console (Ctrl+Shft+J in Chrome), because you have some errors you need to deal with first.

You have an onclick attribute (see below) for the p element.

popup randomNum() getQuote(n)

What is popup? Where have you seen such a function in JavaScript. Also, you have randomNum() getQuote(n) that would really need to be separated by semi-colon. However, I do not see a function in your project called getQuote, so that is going to be a problem.

Also, why are you using new in the following line?

switch (new getQuote){

#3

thank you for reply. popup is the css element that I am trying to tell the popup to have those qualities.

In past projects I never had to separate functions in the html with ; I would just list them one after another.

when I used
switch (new getQuote){
}
I thought that I was creating a new function called getQuote that assigns variable quote to whatever n is set to from randomNum(). and if I say getQuote(n), I would get a random quote called quote from this function.


#4

I assume you mean you want the div with class=“popup” to display a quote when the text “CICK ME FOR A QUOTE!” is clicked. You have to specify where the quote is displayed inside a function (i.e. get Quote which you have not yet created). Your getQuote function would have the Switch statement inside it and it would need to reference the div with class=“pop” using the querySelector function. The getQuote function would make a call to randomNum to generate a random number (1-3) and then it should return the applicable quote (via your Switch statement) so it could be used in getQuote function to display the quote.

If you want to create a function called getQuote, there are many different ways to do it, but that is not one of them. Just create a function like you did with randomNum.

function getQuote(n){
  // do something with n
}

In general, it is best to not put your event handlers in the html section. Put all JavaScript in the JS module and use addEventListener to add click event handlers.

I don’t know what past projects you worked on, so I can not comment on why you were able to do what you say. It appears to me you are not understanding how to make calls to other functions within a function in order to get values returned for use in the function.