Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions js/filterLongWords.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var words = ["hello", "world", "bye"]

var maxlength = 5

var arrLength = []
for (i = 0; i < words.length; i++) {
var lengthOfWords = words[i].length
arrLength.push(lengthOfWords)

console.log (arrLength)
}

var tooLong = []
var justNice = []
for (j = 0; j < arrLength.length; i++) {
console.log(arrLength[i] < maxLength ? (tooLong.push(arrLength[i])) : (justNice.push(arrLength[i])));

}
31 changes: 31 additions & 0 deletions js/fizzbuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// function FizzBuzz (val) {
// for (var val = 0; i < 100; i += 1) {
// if (val % 3 = 0)
//
// }
// }

function FizzBuzz (counter) {

for (counter = 0; counter < 100; counter++) {
if(counter%15===0){
console.log("fizzbuzz")
counter=counter-1
} else {
if(counter%3===0){
console.log("fizz")
counter=counter-1
} else {
if(counter%5===0) {
console.log("buzz")
counter=counter-1
} else {
console.log("number " +counter)
counter=counter-1
}
}
}
}
}

FizzBuzz (10)
28 changes: 28 additions & 0 deletions js/grade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

function grade(val) {
switch (true) {
case (val < 20):
console.log(val + " F");
break;
case (val > 20 && val <= 30):
console.log(val +" E");
break;
case (val > 30 && val <= 50):
console.log(val +" D");
break;
case (val > 50 && val <= 60):
console.log(val +" C");
break;
case (val > 60 && val <= 80):
console.log(val +" B");
break;
case (val > 80 && val <= 100):
console.log(val + " A");
break;
default:
alert("none");
break;
}
}

grade(55)
34 changes: 34 additions & 0 deletions js/phonebook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var phoneBook = {
"Abe": "111-111-1111",
"Bob": "222-222-2222",
"Cam": "333-333-3333",
"Dan": "444-444-4444",
"Ern": "555-555-5555",
"Fry": "111-111-1111",
"Gil": "222-222-2222",
"Hal": "333-333-3333",
"Ike": "444-444-4444",
"Jim": "555-555-5555",
"Kip": "111-111-1111",
"Liv": "222-222-2222",
"Mia": "333-333-3333",
"Nik": "444-444-4444",
"Oli": "555-555-5555",
"Pam": "111-111-1111",
"Qiq": "222-222-2222",
"Rob": "333-333-3333",
"Stu": "444-444-4444",
"Tad": "555-555-5555",
"Uwe": "111-111-1111",
"Val": "222-222-2222",
"Wil": "333-333-3333",
"Xiu": "444-444-4444",
"Yam": "555-555-5555",
"Zed": "111-111-1111"
};



for (var prop in phoneBook) {
console.log (`obj.${prop} = ${obj[prop]}`)
}
9 changes: 9 additions & 0 deletions js/reverse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function reverseString(inputString) {
var newString = " ";
for (var i = inputString.length-1; i >= 0; i--) {
newString += inputString[i];
}
console.log(newString)
}

reverseString('building')
Empty file added js2-answers/.keep
Empty file.
20 changes: 20 additions & 0 deletions js2-answers/filterLongWords.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var words = ["hello", "world", "bye"]

var maxLength = 5

var newWords = ""
for (i = 0; i < words.length; i++) {
var lengthOfWords = words[i].length
if (lengthOfWords < maxLength) {
newWords.push(words[i])
}
console.log(newWords) //yay! got it working with Shumin's help!
}

// //tried to divide the two zzz
// var tooLong = []
// var justNice = []
// for (j = 0; j <= arrLength.length; i++) {
// console.log(arrLength[i] < maxLength ? (tooLong.push(arrLength[i])) : (justNice.push(arrLength[i])));
//
// }
36 changes: 36 additions & 0 deletions js2-answers/fizzbuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// function FizzBuzz (val) {
// for (var val = 0; i < 100; i += 1) {
// if (val % 3 = 0)
//
// }
// }

function FizzBuzz (counter) {

for (counter = 0; counter < 100; counter++) {
if(counter%15===0){
console.log("fizzbuzz")
counter=counter-1
} else {
if(counter%3===0){
console.log("fizz")
counter=counter-1
} else {
if(counter%5===0) {
console.log("buzz")
counter=counter-1
} else {
console.log("number " +counter)
counter=counter-1
}
}
}
}
}

FizzBuzz (10)

//how to loop

//check if a num is divisible by 3 and 5
// x % 3 === 0 && x % 5 === 0
28 changes: 28 additions & 0 deletions js2-answers/grade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

function grade(val) {
switch (true) {
case (val < 20):
console.log(val + " F");
break;
case (val > 20 && val <= 30):
console.log(val +" E");
break;
case (val > 30 && val <= 50):
console.log(val +" D");
break;
case (val > 50 && val <= 60):
console.log(val +" C");
break;
case (val > 60 && val <= 80):
console.log(val +" B");
break;
case (val > 80 && val <= 100):
console.log(val + " A");
break;
default:
alert("none");
break;
}
}

grade(55)
85 changes: 85 additions & 0 deletions js2-answers/phonebook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// var phoneBook = {
// "Abe": "111-111-1111",
// "Bob": "222-222-2222",
// "Cam": "333-333-3333",
// "Dan": "444-444-4444",
// "Ern": "555-555-5555",
// "Fry": "111-111-1111",
// "Gil": "222-222-2222",
// "Hal": "333-333-3333",
// "Ike": "444-444-4444",
// "Jim": "555-555-5555",
// "Kip": "111-111-1111",
// "Liv": "222-222-2222",
// "Mia": "333-333-3333",
// "Nik": "444-444-4444",
// "Oli": "555-555-5555",
// "Pam": "111-111-1111",
// "Qiq": "222-222-2222",
// "Rob": "333-333-3333",
// "Stu": "444-444-4444",
// "Tad": "555-555-5555",
// "Uwe": "111-111-1111",
// "Val": "222-222-2222",
// "Wil": "333-333-3333",
// "Xiu": "444-444-4444",
// "Yam": "555-555-5555",
// "Zed": "111-111-1111"
// };


//var here can be anything, it refers to the KEY names
// for (var contact in phoneBook) {
// console.log(phoneBook[contacts])
// // if (object.hasOwnProperty(variable)) {
// }

var multiObj = {
name: 'Product List',
items: [
{
name: 'Nexus 6P',
price: 800
},
{
name: 'iPhoneX',
price: 1200
}]
}

console.log (multiObj.items)


var totalPrice = 0
for (var init = 0; init < multiObj.items.length; init ++) {
var eachObj = multiObj.items[init]
totalPrice += eachObj.price
}

console.log(totalPrice)









//----------------

//these are all items in an Object

//consle.log(phoneBook[Bob])won't work. Need to "" the key
//so console.log(phoneBook.Bob) works
//console.log(phoneBook["Bob"]) works


// var obj = {'a' : 'helow work'}
//
// var b = 'a'
//
// console.log(obj.b) //should not work need to [] the b
//
// console.log(obj[b])
//arr.unshift(321) will make 321 got the first of the array
13 changes: 13 additions & 0 deletions js2-answers/reverse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function reverseString(inputString) {
var newString = " ";
for (var i = inputString.length-1; i >= 0; i--) {
newString += inputString[i];
}
console.log(newString)
}

reverseString('building')

// for (var i = 0; i < array.length; i++) {
// array[i]
// }