So far, our websites can look good, but they can't *do* anything. Today, we'll change that by learning JavaScript! JavaScript is the programming language of the web that lets you add interactivity, animations, and all sorts of cool features to your pages.
If HTML is the skeleton and CSS is the clothes, JavaScript is the brain and muscles. It's what makes websites come alive! From simple pop-up alerts and prompts to complex games and applications, JavaScript powers the interactive parts of almost every modern website.
JavaScript lets us give instructions to the browser. Let's look at the core concepts you'll use today.
let name = "Student"; and use it later.
function sayHello() { ... } and then "call" it to run the code inside.
onclick attribute in HTML to run a JavaScript function when an
element is clicked.
document.getElementById('output') to select an element and
then change its content or style.
Your mission is to bring the static HTML page to life by wiring up the buttons to the JavaScript
functions. The functions are already written for you in the <script> tag!
Look at the JavaScript functions provided. Your goal is to call the correct function when
each button is clicked using the onclick attribute.
onclick="sayHello()" attribute to it. Now, when you click it,
it should run the sayHello function and ask for your name!
onclick="changeColor()" attribute. Clicking it will now change the
background color of the output box.
onclick="showTime()" attribute. This will display the current time in the
output box.
prompt() in the sayHello function, or add a new color to the
colors array in the changeColor function.
Try adding a new button to your page with its own function. Maybe it could change the text of the
main <h1> element? In our next lesson, we'll dive deeper into DOM
Manipulation to build even more dynamic pages.