//variables names
Variable names can be any word that isn’t a reserved word (such as var). They may not include spaces. Digits can also be part of variable names—catch22 is a valid name, for example—but the name must not start with a digit. A variable name cannot include punctuation, except for the characters $ and _.
//for loop
//prompt for info, and then use that info in a follow-up prompt
var x = prompt("What is your favorite sports team?")
alert("Love that bunch of players.")
//prompt for info and then add conditional terms if specific entry is inputted by user
var numberGuess = prompt("Guess a number. Any number. However, whatever you do, don't type in the number 3")

if (numberGuess == "3" || numberGuess == "three" || numberGuess == "THREE" || numberGuess == "Three") {
alert("I told you not to type in the number 3!") window.location = "https://www.youtube.com/watch?v=oHg5SJYRHA0" }
//falsy and truthy
// Outputs: "Falsy."
logTruthiness(false);
// Outputs: "Falsy."
logTruthiness(null);
// Outputs: "Falsy."
logTruthiness(undefined);
// Outputs: "Falsy."
logTruthiness(NaN);
// Outputs: "Falsy."
logTruthiness(0);
// Outputs: "Falsy."
logTruthiness("");
//logical operators
&& (and) - false seeking
|| (or) - truth seeking
//javascript array methods
.push - add an element on to the end
.pop - remove an element from the end
.unshift - add an element to the front
.shift - remove an element from the front
//append Javascript array elements to html using while loop
for (var i = 0; i < bucket_list.length; i++) {
$( "body" ).append(bucket_list[i] + " ");
console.log(bucket_list[i]);
}
//invoke two arrays using one function/for loop
var append_strings = function (array) {
for (var i = 0; i < array.length; i++) {
$( "body" ).append(array[i] + " ");
}
}

append_strings(recipe)
append_strings(bucket_list)
//pop and shift or add and remove first and last elements from array to add to new array
var scrambled_poem = "roses red are bacon crispy i bacon love and is blue violets are"

var scrambled_array = scrambled_poem.split(" ");
var unscrambled_array = ""

unscrambled_array += scrambled_array.pop() + " " + scrambled_array.shift()

console.log(scrambled_array)
console.log(unscrambled_array)
//use forEach in function to return each item in an array nested inside a literal object
(not all the code, just showing how forEach was used)

dog.toys.forEach(function(item) {
if (item === toy) {
result = dog.name;
//open-ended prompt
prompt("Tell me everything you know.", "...");
//prompt for string, keep prompting until something is entered
do {
var yourName = prompt("Who are you?");
} while (!yourName);

console.log(yourName);
//computer 2^10 (two to the tenth power) using for loop, without a while loop
var result = 1; for (var counter = 0; counter < 10; counter = counter + 1)
result = result * 2;

console.log(result);
//switch and cases
switch (prompt("What is the weather like?")) {
case "rainy":
console.log("Remember to bring an umbrella.");
break;
case "sunny":
console.log("Dress lightly.");
case "cloudy":
console.log("Go outside.");
break;
default:
console.log("Unknown weather type!");
break;
}
//keywords and reserved words
(don’t use them for variable names)

break case catch class const continue debugger default delete do else enum export extends false finally for function if implements import in instanceof interface let new null package private protected public return static super switch this throw true try typeof var void while with yield
//basic function structure
var square = function(x)
{ return x * x; };

console.log(square(12));
//conditional Logic Flow
Booleans & Comparators (Type the following into your console, can you guess what will be returned?)

- > !true
- > !false
- > !!false
- > !!true
- > !!"type coercion"
- > !!"all strings are 'truthy' except for..."
- > !!""
- > true && true
- > true && false
- > false && true
- > false && false
- > true || true
- > true || false
- > false || true
- > false || false
- > true && "what does this evalute to?"
- > false && "and this?"
- > true || "sigh, i'm not needed"
- > false || "default value"
//write a while loop that counts from 0 to 50 by twos
var n = 0
console.log("I am called the Count... because I really love to count!")

while (n <= 50) {
console.log(n)
n += 2
}

console.log('fin!')
//count from 1 to 10, with a comma after each integer
var n = 0

while (n <= 10) {
if (n < 10){
console.log(n+",")
} else {
console.log(n)
}
n++
}
//iterate over property/properties in object, the for in loop
for (var i in car) {
if (i === "color") {
console.log(car.color)
$("#favorite_car_colors").append(car.color)
}
}
//iterate over key in object, the for in loop
for (var key in obj) {
var value = obj[key]
if (value === "down") {
console.log(key)
$("#direction_headed").append(key)
}
}
//use for in to iterate/loop over and find the value of a property in an object
for (var i in obj) {
if (i === target_key) {
console.log(obj[i])
$('#direction_headed').append(obj[i])
}
}
//take values from array and place them into object using for loop
var numbers = [2, 4, 5, 37, 0]
var doubled_numbers = {}

for (var i = 0; i < numbers.length; i++) {
key = numbers[i]
value = numbers[i] * 2
doubled_numbers[key] = value
$("#doubles").append("

" + key + " doubled is " + value + "

")
}
//find even numbers of an array
var a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
b = [];

for (var i = 0; i < a.length; ++i) {
if ((a[i] % 2) === 0) {
b.push(a[i]);
}
}
//create object using bracket notation
var gradebook = new Object()
//get average of an array, an array that is part of a nested object within a property of an Object
gradebook.getAverage = function(name){
return average(gradebook[name].testScores);
}

var average = function(scores){
var total = 0
for (var i in scores)
total += scores[i];
return total / scores.length
}