Random Quote Generator - A small javascript project
Random Quote Generator
A Random Quote Generator is capable of pulling quotes randomly using Math Library.
The web page displays a random quote from a collection and upon the click of a button, it randomly generates a new quote.
Step 1: To Create HTML File.
In HTML file we have to link javascript file so that our javascript code will be able interact with the HTML document.
We will also add text within the <title> tags, add an <h1> element, create a <div> element with an id name of quoteDisplay, and also a <button> element with an onclick attribute with "newQuote()" passed into it.
Step 2: To Create Javascript File
In this file, I googled "Best Quotes", and copied 15 quotes, then placed in an array separated by commas.
Make sure you place your quotes in single or double quotation marks.
Now we need to create newQuote() function, in that we need to generate a random whole number that ranges from 0 to the length of our quotes array.
Now we need to use to use the value of randomNumber to randomly retrieve a quote from the quotes array and place the quote into our HTML document and display it to our users.
MISSION COMPLETED✌
To decorate the CSS file, comment on the post
THANKS FOR READING AND HAPPY CODING💜
Comments
Post a Comment