Show a random number on page load
Get your web page ready
index.html by moving your CSS to an external file, like this:
<!-- Your CSS goes in the styles.css file --> <link rel="stylesheet" href="styles.css"> </head>
Write a random number function
script block, write a function that returns a random number from 1 to 9. Have a look at Math.random() on the Mozilla Developer Network.
What’s the function’s name? What are it’s parameters (sometimes called arguments)? What does
Next we’ll need to find a
div on our page. Let’s look at HTML documents in more detail.
You can find elements in the DOM by their
id or by their
class. There are a couple ways of doing this. Have a read about these on the Mozilla Developer Network about:
Write a function that updates the HTML
Each function should only do one thing, so now let’s write another function that finds your
div and uses the random number function you wrote above.
Once you’re finished, you’ll need to call your function. How and where do you do this?
One you’re done, every time the page loads you should see a new random number. Yay!
Add your files to your repository
Once you are done, add your changes to git by using these commands:
git statusto see what changed.
git add index.htmlto add the changes you made in
git add styles.cssto add the
styles.cssfile to git.
git commit -m "your message"to commit your changes.
git push origin masterto push your changes to GitHub.