Skip to content

Instantly share code, notes, and snippets.

@prettyok
Forked from CLofton/2016_JS_Midterm.js
Last active March 20, 2016 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prettyok/818cd2110e02600d3f52 to your computer and use it in GitHub Desktop.
Save prettyok/818cd2110e02600d3f52 to your computer and use it in GitHub Desktop.
//Intermediate Midterm
// 1. How do you make comments and why do you make them?
//
// You use comments to explain why you wrote the code the way you did. This makes it easier for another person to edit your code, or can make it easier to edit your own code at a later date.
// 2. Set 3 variables with different data types and console.log them.
var varOne = "String";
var varTwo = 2;
var varThree = false;
console.log(varOne, varTwo, varThree);
// 3. What are the five primitive data types you have been using. Provide an example of each.
bolean (true / false), string ("String"), number (9), null (var futureStudentName = null;), undefined would be thr result of (var userName; console.log(userName);)
// 4. Create a function that console.logs the remainder of 2 numbers.
function modQuestion = (9 % 2);
console.log(modQuestion);
// 5. Write an example of an if statement.
if (10 > 2) {
alert("It is greater");
}
// 6. Explain what “scope” means and why it’s important.
Global scope refers to something, like a variable, that applies to a whole block of code. Local Scope refers to something within a function.
// 7. Create an array and console.log the 3rd item in the array.
presidents = ["clinton", "carter", "obama", "ford", "johnson"];
console.log(presidents[2]);
// 8. Create an object and demonstrate how to access a value in it.
function carIdentifier (size, color, type) {
this.size = size;
this.color = color;
this.type = type;
}
// 9. Demonstrate how to add a key/value pair to your array.
// 10. Create a for loop that prints out all the multiples of 3 between 1 and 100.
for (var = i; i >= 3; i++; {
// 10. Create a while loop that prints out all the multiples of 7 between 1 and 100 in reverse order.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment