Skip to content

Instantly share code, notes, and snippets.

@pieroapretto
Forked from CLofton/2016_JS_Midterm.js
Last active March 3, 2016 01:16
Show Gist options
  • Select an option

  • Save pieroapretto/2b7834376f639d092fb6 to your computer and use it in GitHub Desktop.

Select an option

Save pieroapretto/2b7834376f639d092fb6 to your computer and use it in GitHub Desktop.
//Intermediate Midterm
// 1. How do you make comments and why do you make them?
//You make comments with '//'. It helps to keep track of your logic for future examination.
// 2. Set 3 variables with different data types and console.log them.
console.log(4);
console.log('4');
console.log(true);
// 3. What are the five primitive data types you have been using. Provide an example of each.
/* string ex: "tacos"
numbers ex: 9
Boolean ex: true
undefined ex: console.log(undefined)
null ex: var notAValue = null;
*/
// 4. Create a function that console.logs the remainder of 2 numbers.
function remains() {
console.log(9 % 2);
console.log(8 % 2);
}
// 5. Write an example of an if statement.
if (5>8) {
console.log('a');
}
else if (5 === 8) {
console.log('b');
}
else {
console.log('c');
}
// 6. Explain what “scope” means and why it’s important.
/* scope is the parameters of where any given value or variable can be accessed. For example, variables declared in a function cannot be accessed
outside a function. However, a variable declared outside a function can be access in any function, hence the name "global variable" */
// 7. Create an array and console.log the 3rd item in the array.
var array = ['a','b','c','d'];
console.log(array[2]);
// 8. Create an object and demonstrate how to access a value in it.
var object = {
one: 'a'
two: 'b'
}
console.log(object.one);
// will print a
// 9. Demonstrate how to add a key/value pair to your array.
var array = {
one: 1,
two: 2
};
array['one'] = 'new number';
console.log(array['one']);
//will print new number where the numerical value '1' use to be.
// 10. Create a for loop that prints out all the multiples of 3 between 1 and 100.
for(var i = 1; i <100; i++) {
if (i % 3 === 0) {
console.log(i);
}
}
// 10. Create a while loop that prints out all the multiples of 7 between 1 and 100 in reverse order.
var i = 0;
while(i < 100) {
i++
if(i % 7 === 0) {
console.log(i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment