0
0
Intro to Computingfundamentals~5 mins

JavaScript for interactivity in Intro to Computing - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is JavaScript used for in web pages?
JavaScript is used to make web pages interactive. It can respond to user actions like clicks, typing, and mouse movements to change the page without reloading.
Click to reveal answer
beginner
Explain the role of an event listener in JavaScript.
An event listener waits for a specific action (like a click) on a webpage element and then runs a function when that action happens.
Click to reveal answer
beginner
What does the following JavaScript code do?<br>
document.getElementById('btn').addEventListener('click', () => { alert('Hello!'); });
This code waits for a click on the element with id 'btn'. When clicked, it shows a popup message saying 'Hello!'.
Click to reveal answer
beginner
Why is JavaScript called a 'client-side' language?
Because JavaScript runs in the user's web browser (the client), not on the web server. This lets pages react quickly to user actions.
Click to reveal answer
intermediate
How does JavaScript change the content of a web page without reloading it?
JavaScript can change the page by modifying the HTML elements directly using the Document Object Model (DOM), so the page updates instantly.
Click to reveal answer
What does an event listener do in JavaScript?
AWaits for user actions and runs code when they happen
BLoads the web page faster
CChanges the style of the page automatically
DSaves data to the server
Which JavaScript method selects an element by its ID?
Adocument.querySelectorAll()
Bdocument.createElement()
Cdocument.getElementById()
Ddocument.addEventListener()
What happens when you run this code?<br>
button.addEventListener('click', () => { console.log('Clicked!'); });
AShows an alert box
BChanges the button text to 'Clicked!'
CReloads the page
DLogs 'Clicked!' to the console when the button is clicked
Why is JavaScript important for web interactivity?
AIt makes pages respond to user actions without reloading
BIt styles the page with colors and fonts
CIt stores data on the server
DIt creates the page layout
Which of these is NOT a typical use of JavaScript on a web page?
AAnimating images or buttons
BCreating the server database
CChanging the page content dynamically
DValidating form input before sending
Describe how JavaScript makes a web page interactive using an example.
Think about clicking a button and what happens next.
You got /4 concepts.
    Explain the role of the Document Object Model (DOM) in JavaScript interactivity.
    Imagine the web page as a tree of elements JavaScript can change.
    You got /3 concepts.