Created
June 5, 2017 17:52
-
-
Save craigwendel/bc85714f9f18476ea1c4c7858b4a72c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Intro to JavaScript Assessment</title> | |
</head> | |
<body> | |
Intro to JS | |
<script type="text/javascript" src="main.js"> | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Answer the following questions in this file using comments without running the code | |
// 1. | |
// What does `givenName` equal right now? | |
var givenName; | |
// A: | |
console.log("undefined"); | |
// 2. | |
// What is `givenName` set to right now? | |
givenName = "Tim"; | |
// A: | |
console.log("Tim"); | |
// 3. | |
// What is `givenName` set to right now? | |
givenName = givenName; | |
// A: | |
console.log("Tim"); | |
// 4. | |
// What is `greeting` set to? | |
var greeting = "Hello, how are you? " + givenName; | |
// A: | |
console.log("Hello, how are you Tim?"); | |
// 5. | |
// What is `math` set to? | |
var high = 50; | |
var low = 10; | |
var math = high - low; | |
// A: | |
console.log(40); | |
// 6. | |
// What is `math` set to? | |
math = high - "5"; | |
// A: | |
console.log("505"); | |
// 7. | |
// Create a variable to calculate Tim's age | |
// The answer should read "Tim is 33 years old" | |
// The answer shoud not be written in a comment. | |
var born = 1984; | |
var today = 2017; | |
// A: | |
var timsAge = today - born; | |
console.log(timsAge) | |
console.log(33); | |
// 8. | |
// Adjust this code. Store some information in the following variables. | |
// A: | |
var yourName = "Craig"; | |
var instructorName = "Kenji"; | |
// 9. | |
// Update the variables `yourName` and `instructorName` so the expression below reads correctly. | |
// A: | |
console.log(statement); | |
// This statement should read correctly | |
var statement = yourName + " is taking a class at The Iron Yard, my instructor's name is " + instructorName; | |
// 10. | |
// We've created a variable named after each primitive type. | |
// Use the `=` operator to assign a value to each variable matching the type in the name. | |
var myNumber; | |
var myString; | |
var myBoolean; | |
// This one's a little tricky - think carefully about what makes a value "undefined"! | |
var myUndefined; | |
// A: | |
var myNumber= 30; | |
var myString = "30"; | |
var myBoolean = true; | |
var myUndefined; | |
// For questions 11 - 19: List which boolean value will be stored in each variable. (Remember: `==` does not check data type) | |
// 11. | |
var x = (false == 0); | |
// A. | |
console.log(true); | |
// 12. | |
var y = (false == ""); | |
// A. | |
console.log(true); | |
// 13. | |
var z = (0 == ""); | |
// A. | |
console.log(true); | |
// 14. | |
var a = (null == null); | |
// A. | |
console.log(true); | |
// 25. | |
var b = (undefined == undefined); | |
// A. | |
console.log(true); | |
// 16. | |
var c = (undefined == null); | |
// A. | |
console.log(true); | |
// 17. | |
var d = (null == false); | |
// A. | |
console.log(false); | |
// 18. | |
var e = (NaN == null); | |
// A. | |
console.log(true); | |
// 19. | |
var f = (NaN == NaN); | |
// A. | |
console.log(false); | |
// 20. | |
// Fix the `if...else` statement below by adding an `if` keyword and conditional expression. | |
// Use the variable `thirsty` as part of your conditional expression. | |
// A: | |
var thirsty = true; | |
if (thirsty === true) | |
{ | |
console.log("I'm parched!"); | |
} else { | |
console.log("I've had enough to drink."); | |
} | |
// For questions 21 - 29 list which statement will be logged. | |
// 21. | |
var x; | |
if(x){ | |
console.log("True!"); | |
} else { | |
console.log("False!"); | |
} | |
// A: | |
console.log("False"); | |
// 22. | |
if(""){ | |
console.log("True!"); | |
} else { | |
console.log("False!"); | |
} | |
// A: | |
console.log("False!"); | |
// 23. | |
// this expression will set x to NaN | |
var x = 1 * undefined; | |
if(x){ | |
console.log("True!"); | |
} else { | |
console.log("False!"); | |
} | |
// A: | |
console.log("True"); | |
// 24. | |
if(false){ | |
console.log("True!"); | |
} else { | |
console.log("False!"); | |
} | |
// A: | |
console.log("False!"); | |
// 25. | |
if(-5 && 5){ | |
console.log("True!"); | |
} else { | |
console.log("False!"); | |
} | |
// A: | |
console.log("False"); | |
// 26. | |
if("Hello World!"){ | |
console.log("True!"); | |
} else { | |
console.log("False!"); | |
} | |
// A: | |
console.log("True!"); | |
// 27. | |
if({}){ | |
console.log("True!"); | |
} else { | |
console.log("False!"); | |
} | |
// A: | |
console.log("True!"); | |
// 28. | |
if({name: "Yehuda Katz"}){ | |
console.log("True!"); | |
} else { | |
console.log("False!"); | |
} | |
// A: | |
console.log("True"); | |
// 29. | |
if(new Date()){ | |
console.log("True!"); | |
} else { | |
console.log("False!"); | |
} | |
// A: | |
console.log("True!"); | |
// 30. | |
// Link this file to the sibling `index.html` document, open the file in your browser and request an instructor. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment