Coding Cheat Sheet
Question / Term | Explanation / Definition |
What is a variable? What do we use them for? How do we create them? | A variable is a term that can store information. Variables can be reffered to in different instances in order to make them function in different ways or use multiple pieces of info in conjunction with one another. They can be created by using "var" and then whatever you would like the name the variable afterwards. Variables go in the body of an html file. Example: "var x" |
What is a function? What is their syntax/structure? | A function is like a recipe in javascript. It is a set of things that will be done under one singular term. They may already be defined or you can create them yourself. You can call a function by typing the function and then (). Example: If the name of the function was function, then type "function()" |
When do we use conditional statements? (i.e. if else statements? What is their syntax and structure?) |
We use conditional statements when we want to make something happen in a certain circumstance whether that be when a certain event happens or something to only apply to ceratin variable(s). This makes it possible to further customize your code. For example, you could use an if else statement to specify that you want text to pop that says "hello" only if square_1 is clicked. So, within an event listener for when you click, your code would like this: if (square.id == "square_1") text1.innerHTML = "hello" |
What are the differemt types of data in javascript? | Strings, numbers, booleans, undefined, and null. |
What is an array? When do we use them and how do we write them? | An array is a set of shapes that are in rows and columns. We can use them to neatly arrange things such as photos, icons, etc. You can write them by creating a javascript function to create the shape that you want and make sure that you set the style.display to "inline-block". Then, run that function however many times you would like that shape to show up in your array. |
How do we refer to the different elements in an array? | You can refer to the different elements in an array via their ids. |
What is an event listener? When do we use then? What is their syntax/structure? | An event listener is a way that you can have user interaction trigger something to happen. ASK FOR EXAMPLE IN CLASS !!! }) |
What is Math.random()? What does it do? When do we use it? | Math.random() is a function that chooses a random number. You can specify the range from which it will choose this number. You can use ti when you would like to randomize pretty much anything, whether that be numbers using the function alone or even something like colors for example. In order to use it for colors, you would have to make a list with the colors it can choose from and then make the number chosen align with each of the ids of the colors. |