Created
February 6, 2012 04:19
-
-
Save recursive/1749614 to your computer and use it in GitHub Desktop.
Answers to appendTo JS 101
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
// These exercises are meant to get you familiar with basic variable declerations and JavaScript primitive types. The exercises below will as you to print things to the console. This can be done with a console.log function call. Example: | |
console.log( "hello there." ); | |
// If you choose to "run" the fiddle using the above run button, you'll see the console log statement in the result pane to the left. | |
// The questions will give you an answer area to fill in with your console.log statements. | |
// Question1 : Log to the console only those values that are considered "truthy" | |
var q1Var1 = "hello", | |
q1Var2 = 0, | |
q1Var3 = true, | |
q1Var4 = "false", | |
q1Var5 = -1, | |
q1Var6 = undefined, | |
q1Var7 = null, | |
q1Var8; | |
// BEGIN Question 1 Answer | |
if ( !!q1Var1 ) { console.log( q1Var1 ) } | |
if ( !!q1Var2 ) { console.log( q1Var2 ) } | |
if ( !!q1Var3 ) { console.log( q1Var3 ) } | |
if ( !!q1Var4 ) { console.log( q1Var4 ) } | |
if ( !!q1Var5 ) { console.log( q1Var5 ) } | |
if ( !!q1Var6 ) { console.log( q1Var6 ) } | |
if ( !!q1Var7 ) { console.log( q1Var7 ) } | |
if ( !!q1Var8 ) { console.log( q1Var8 ) } | |
// END Question 1 Answer | |
// Question 2: Log to the console the items that are considered primitive types. | |
var q2Var1 = "hi there.", | |
q2Var2 = String( "another string here." ), | |
q2Var3 = Number( 1.41 ), | |
q2Var4 = !!Boolean( true ); | |
// BEGIN Question 2 Answer | |
if( typeof q2Var1 !== 'object' ) { console.log( q2Var1 ) } | |
if( typeof q2Var2 !== 'object' ) { console.log( q2Var2 ) } | |
if( typeof q2Var3 !== 'object' ) { console.log( q2Var3 ) } | |
if( typeof q2Var4 !== 'object' ) { console.log( q2Var4 ) } | |
// END Question 2 Answer | |
// Question 3: Print the concatenation of theses two strings to the console. | |
var q3Var1 = "hello, ", | |
q3Var2 = "is it me you're looking for?"; | |
// BEGIN Question 3 Answer | |
console.log( q3Var1 + q3Var2 ) | |
// END Question 3 Answer | |
// Question 4: Coerce the first variable to a number, add the two variables together and log the result to the console. | |
var q4Var1 = "24", | |
q4Var2 = 18; | |
// BEGIN Question 4 Answer | |
console.log( parseInt( q4Var1, 10 ) + q4Var2 ) | |
// END Question 4 Answer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment