Last active
June 7, 2018 06:09
-
-
Save nitharios/d822397536cddfaa5df194f1fd3b4db9 to your computer and use it in GitHub Desktop.
js_basics 20180606
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
// Comments are text that will not be executed in your code. Rather comments are for other programmers to read. | |
// Single line comments start with // | |
/* Multiple line comments start with*/ /* and end with */ | |
/* All of the exercises below are commented out. Write your Javascript code after each exercise. */ | |
/* Variables and Data Types */ | |
/*Console.log each variable and test your code in the terminal using the Node REPL*/ | |
/*i.e.*/ | |
var pet = "sebastian the pug"; | |
console.log(pet); // <= this should print out sebastian the pug | |
/* | |
* #1 | |
* Variables with a "String" value | |
* Declare variables named firstName, lastName, birthPlace, favFood, favDrink, favSong, favAnimal, favColor, favSport, favDoughnut. | |
* Assign your own string values to each variable and console.log each variable. | |
*/ | |
var firstName = 'Nathan'; | |
var lastName = 'N'; | |
var birthPlace = 'Hawaii'; | |
var favFood = 'pizza'; | |
var favDrink = 'POG'; | |
var favSong = 'Hello'; | |
var favAnimal = 'dog'; | |
var favColor = 'blue'; | |
var favSport = 'soccer'; | |
var favDoughnut = 'cake'; | |
/* | |
* #2 | |
* Variables with a Number value | |
* | |
* Declare variables named favNumber, yourShoeSize, thatOnePrinceSong, floorsAlaMoanaHotel, numOfJapanPrefectures, numOfABCstoresinHi, and cheesecakesFlavAtCheeseCakeFac | |
* | |
* Assign your own number values to each variable and console.log each variable. | |
*/ | |
/* | |
* #3 | |
* Variables with a Boolean value | |
* | |
* Declare variables named likesMcDonalds, eatsDoughnuts and ownsRedShoes. | |
* | |
* Assign your own boolean values to each variable and console.log each variable. | |
* | |
* | |
* Now, use comparison and logic operators (>, <, >=, <=, ===, !==) to make the following variables True of False | |
* | |
* Console.log each variable. | |
* | |
*/ | |
//For example: | |
//Make me True: | |
var booya1 = 3 > 2; | |
console.log('1', booya1); | |
//Make me False: | |
var booya2 = likesMcDonalds === ownsRedShoes; | |
console.log('2', booya2); | |
//Make me True: | |
var booya3 = likesMcDonalds !== ownsRedShoes; | |
console.log('3', booya3); | |
var likesMcDonalds = true; | |
var eatsDoughnuts = true; | |
var ownsRedShoes = false; | |
//Make me False: | |
var booya4 = eatsDoughnuts === ownsRedShoes; | |
console.log('4', booya4); | |
//Make me True: | |
var booya5 = likesMcDonalds > ownsRedShoes; | |
console.log('5', booya5); | |
//Make me False: | |
var booya6 = likesMcDonalds <= ownsRedShoes; | |
console.log('6', booya6); | |
/* | |
* #4 | |
* Variables with a Null value | |
* | |
* Declare variables named completedPrepClass, traveledToMars and buyVicADrink. | |
* | |
* Assign a null value to each variable and console.log each variable. | |
*/ | |
/* | |
* #5 | |
* Variables with a undefined value. | |
* | |
* Declare a variable named superBowlChamps, nextPres and hawaiiRail. | |
* | |
* Do not assign a value to the variable and console.log each variable. | |
*/ | |
/* | |
* #6 | |
* Variables with an Array value | |
* | |
* Declare a variable named plateLunch and assign it an array containing 5 of your favorite lunch items. | |
* Declare a variable named `donutBox` and assign it an array containing 5 donuts of your choosing. | |
* Declare a variable named `westCoast` and assign it an array containing states found on the west coast of the US. | |
* Declare a variable named `lotteryResult and assign it an array containing 5 random numbers. | |
* Declare a variable named `hamajang` and assign it an array containing 6 different data types. | |
* Declare a variable named `dynamicDuos` and assign it an array containing 3 arrays, with each array containing items that match with one another. | |
* | |
* Console.log each variable. | |
*/ | |
var plateLunch = ['sandwich', 'drink', 'fruit', 'vegetables', 'chocolate']; | |
console.log(plateLunch); | |
var donutBox = ['maple bar', 'bavarian', 'chocolate', 'apple fritter', 'Simpson']; | |
console.log(donutBox); | |
var hamajang = ['hello world', 3, true, null, undefined, []] | |
console.log(hamajang); | |
/*7 | |
* Accessing values in Arrays | |
* var partyList = ["carrot cake", "gin & tonic", "kalua pork nachos", "double stuff oreos", "cool ranch doritos", "orange chicken"]; | |
Console.log the entire array. | |
Console.log the length of this array. | |
Console.log only "carrot cake" from this array. | |
Console.log only "cool ranch doritos" from this array | |
*/ | |
var partyList = ["carrot cake", "gin & tonic", "kalua pork nachos", "double stuff oreos", "cool ranch doritos", "orange chicken"]; | |
console.log(partyList); | |
console.log(partyList.length); | |
console.log(partyList[0]); | |
console.log(partyList[5]); | |
console.log(partyList[4]); | |
console.log(partyList[partyList.length-2]); | |
/* | |
* #8 | |
* Concatenation | |
* Concatenate the variables `firstName` and `lastName` from exercise 1 and store them into a new variable called `fullName` (don't forget to include a space between the firstName and lastName). | |
* | |
* Using the fullName and birthPlace variables, console.log the following: | |
* | |
* "Hi my name is fullName and I was born in birthPlace." | |
* | |
* i.e "Hi my name is Bruce Wayne and I was born in Gotham." | |
*/ | |
/* | |
* #9 | |
* Arithmetic | |
* Variables with the outcome of an arithmetic operation. | |
* Declare two variables, `num1` and `num2` and assign each of these variables a number of your choosing. | |
* Next perform the following arithmetic operations: | |
* Add the two variables and store it to new variable named sum. | |
* Subtract the two variables and store it to a new variable named difference. | |
* Mulitply the two variables and store it to a new variable named product. | |
* Divide the two variables and store it to a new variable named quotient. | |
* Find the remainder (modulus) of the two variables and store in to a new variable names leftOver. | |
* | |
* Console.log each new variable. | |
*/ | |
/* | |
* #10 | |
* Comparisons & Logic | |
* Variables with the outcome of a comparison operation: | |
* | |
* Declare a variable named `isStrictlyEqual` and compare two strings "Tacocat" and "tacocat" using the strict equality (===). | |
* Declare another variable named `isLooselyEqual` and compare the two strings "Tacocat" and "tacocat" using equality (==). | |
* Declare a variable named `sameNum` and compare a string "5" and a number 5 using strict equality. | |
* Declare another variable named `sameNumba` and compare a string "5" and a number 5 using equality. | |
* Console.log the variables. Do you see the difference between strict equality vs. equality? | |
*/ | |
var isStrictlyEqual = "Tacocat" === "tacocat"; | |
console.log(isStrictlyEqual); | |
var isLooselyEqual = "Tacocat" == "tacocat"; | |
console.log(isLooselyEqual); | |
/* | |
* #11 | |
* Logical AND Logical OR | |
* Use comparison and logic operators (>, <, >=, <=, ===, !==) with the logical && and logical || to make the following variables True of False: | |
*/ | |
//Use && to make me True | |
var booya7 = 5 > 3 && 2 > 1; | |
console.log('7', booya7); | |
//Use && to make me False | |
var booya8 = 4 < 3 && 3 === 3 ; | |
console.log('8', booya8); | |
//Use || to make me True | |
var booya9 = 5 > 2 || 3 < 1 ; | |
console.log('9', booya9); | |
//Use || to make me False | |
var booya10 = 3 > 4 || 5 > 6 ; | |
console.log('10', booya10); | |
//Console.log each variable | |
/* | |
* #12 | |
* Assignments | |
* Variables with the outcome of an assignment operation (+=, -=, *=, /=, %=): | |
* | |
* Declare a variable named `myNum` and assign it with a number of your choosing. | |
* | |
* Change the value of the muNum variable by using the assignment operators and console.log myNum after each assignment. | |
*/ | |
var count = 1; | |
count += 1; | |
console.log('count', count); | |
//increment and assign 3 (+=): | |
//decrement and assign 1 (-=): | |
//multiple and assign 2 (*=); | |
//divide and assign 5 (/=); | |
//modulo and assign 4 (%=); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment