JS Flashcards
What is JS?
Dynamic programming language that’s used for web development, web applications, game development, and lots more.
What does JS allow you to do?
To implement dynamic features on web pages that cannot be done with only HTML and CSS.
What are some examples of JS?
Click to see dropdown menu, extra content added to a page, and dynamically changing element colors on a page, …. you’re seeing the effects of JavaScript.
In the index.html file we enter:
what does this do?
It’s doing the same job as the <link></link> element for CSS
It applies the JavaScript to the page, so it can have an effect on the HTML, CSS and anything else on the page.
Explain: The function called querySelector()
The querySelector() method returns the first element that matches a CSS selector.
What are variables?
Variables are containers that store values.
You start by declaring a variable with the “let” keyword, followed by the name you give to the variable:
EG: let myVariable;
After declaring a variable, you can give it a value: for example :
myVariable = “Bob”;
How can we retrieve the value ?
by calling the variable name:
myVariable;
Variables may hold values that have different DATA TYPES…can you name some?
string : eg - let myVariable = “Bob”
number : eg - let myVariable = 10;
Boolean: ( true / false) : eg let myVariable = true;
array ( store multiple values in a single reference.) : eg - et myVariable = [1,’Bob’,’Steve’,10];
object ( Everything in JavaScript is an object and can be stored in a variable) EG: let myVariable = document.querySelector(‘h1’);
Give an example of a comment?
snippets of text that can be added along with code. The browser ignores text marked as comments.
/*
Everything in between is a comment.
*/
OR
//This is a comment
Give an example of an Operator?
mathematical symbol that produces a result based on two values (or variables).
EG: Assignment - the = symbol ;
let myVariable = ‘Bob’;
Give an example of a conditional ?
code structures used to test if an expression returns true or not.
EG: A very common form of conditionals is the if…else statement.
let iceCream = “chocolate”;
if (iceCream === “chocolate”) {
alert(“Yay, I love chocolate ice cream!”);
} else {
alert(“Awwww, but chocolate is my favorite…”);
}
Give an example of a function?
way of packaging functionality that you wish to reuse.
EG: alert(“hello!”);
Give an example of an event?
Real interactivity on a website requires event handlers
These are code structures that listen for activity in the browser, and run code in response. The most obvious example is handling the click event, which is fired by the browser when you click on something with your mouse.
document.querySelector(“html”).addEventListener(“click”, function () {
alert(“Ouch! Stop poking me!”);
});
Now lets watch this video!
https://www.youtube.com/watch?v=1HUS1OvpX80
How can we build our skills in web development ?
Watch google videos, eg : net ninja, stop and start and follow along by doing the coding on VS code with the video
Use Chat GPT: ask questions about how to change , adapt and build code
Use co-pilot in VS code: see what co-pilot delivers and then try to undertsnad d why that code was useful