-
Click on the Fork icon at the top right corner of the repository page on GitHub.com.
-
On the next screen, click the green Create fork button to create your own copy of the original repository.
-
Once the fork is created, click the green Code button and select Open with GitHub Desktop.
-
In GitHub Desktop, clone the repository by choosing a Local Path where you want to store a copy on your computer. When prompted about how you plan to use this fork, select For my own purposes.
-
In this exercise, the HTML and CSS are provided to you as index.html and css/style.css. Note: You should not modify the css/style.css file; focus only on the JavaScript functionality.
-
Link to the JavaScript file
js/script.jsfrom the provided HTML. -
Ensure
"use strict"is at the top of your script. -
In the script.js file, create an
arraynamedquotesusing aconstthat contains at least five different quotes as strings. -
Define a
functionwithout parameters namedgetRandomQuote(). -
Inside the
function getRandomQuote()make anif statementthat checks if thequotes array's lengthis equal to zero andreturnfollowing text iftrue- 'No quotes available'. -
Inside the
function getRandomQuote()UseMath.random()andMath.floor()to generate a random number multiplied with thelengthof thearrayand stored in a variable namedrandomIndexusingconst. -
Use the
returnmethod in javaScript to get a quote from the array at the randomIndex position. Here is an example:return quotes[randomIndex];
-
Define a new
functionwithout parameters nameddisplayRandomQuote. -
Inside the
function displayRandomQuote()call the functiongetRandomQuote()and store its returned value in the variable namedrandomQuoteusingconst -
Inside the
function displayRandomQuote()- find the HTML element withid="quotes"usinggetELementByIDand sets its text to the value stored inrandomQuote. -
Outside the
function displayRandomQuote()- find the HTML element withid="displayQuoteBtn"and add anaddEventListenerthat take action when the userclickon thebuttonand make a call to the functiondisplayRandomQuote(). Here is an example on how you find an element combined with anaddEventListener:const document.getElementById("idname").addEventListener('click', nameOfFunction);
-
Open Go Live in your VS Code editor and check that the content has been updated.