Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
adding Js3 files
  • Loading branch information
chichiglacierz committed Aug 14, 2019
commit a495ecc988cbffd0373599de4fe09549af4f3907
33 changes: 14 additions & 19 deletions Week3/homework/step2-2.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
'use strict';
function sayThree(number) {
console.log(`your number ${number} is divisible by 3`);
}

function sayFive(number) {
console.log(`your number ${number} is divisible by 5`);
}

function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) {
//creating an empty number array and populating it:
// creating an empty number array and populating it:

const numbers = [];
for (let i = startIndex; i <= stopIndex; i++) {
numbers.push[i];
//divisible by 3?

// divisible by 3?
if (i % 3 === 0) {
threeCallback[i];
console.log(threeCallback(i));
} else if (i % 5 === 0) {
fiveCallback[i];
console.log(fiveCallback(i));
}
}
}

// Replace this comment and the next line with your code
console.log(startIndex, stopIndex, threeCallback, fiveCallback, numbers);

//creating functions displaying output to user
function sayThree(number) {
// Replace this comment and the next line with your code
console.log('${number} is divisible by 3');
}

function sayFive(number) {
// Replace this comment and the next line with your code
console.log('${number} is divisible by 5');
}
// console.log(startIndex, stopIndex, threeCallback, fiveCallback, numbers);

threeFive(10, 15, sayThree, sayFive);

module.export = isDivisible;

// Do not change or remove anything below this line
module.exports = threeFive;
34 changes: 24 additions & 10 deletions Week3/homework/step2-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
function repeatStringNumTimesWithFor(str, num) {
// eslint-disable-next-line prefer-const
let result = '';

if (num <= 0) {
result = '';
} else {
for (let i = 0; i < num; i++) {
result += str;
}
}
// Replace this comment and the next line with your code
console.log(str, num, result);

Expand All @@ -13,30 +19,38 @@ function repeatStringNumTimesWithFor(str, num) {

console.log('for', repeatStringNumTimesWithFor('abc', 3));

//***********************************

// Use a 'while' loop
function repeatStringNumTimesWithWhile(str, num) {
// eslint-disable-next-line prefer-const
let result = '';

// Replace this comment and the next line with your code
console.log(str, num, result);

let counter = 0;
while (counter < num) {
result += str;
counter++;
}
return result;
}

console.log('while', repeatStringNumTimesWithWhile('abc', 3));

// Use a 'do...while' loop
function repeatStringNumTimesWithDoWhile(str, num) {
// eslint-disable-next-line prefer-const
let result = '';

// Replace this comment and the next line with your code
console.log(str, num, result);

let i = 0;
if (num > 0) {
do {
result += str;
i++;
} while (i < num);
}
return result;
}

// Replace this comment and the next line with your code
//console.log(str, num, result);

console.log('do-while', repeatStringNumTimesWithDoWhile('abc', 3));

// Do not change or remove anything below this line
Expand Down
3 changes: 3 additions & 0 deletions Week3/homework/step2-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

function Dog() {
// add your code here
this.name = 'Roger';
this.color = 'black';
this.numLegs = 4;
}

const hound = new Dog();
Expand Down
7 changes: 6 additions & 1 deletion Week3/homework/step2-5.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
function multiplyAll(arr) {
// eslint-disable-next-line
let product = 1;
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
product = product * arr[i][j];
}
}

// Replace this comment and the next line with your code
console.log(arr, product);
// console.log(arr, product);

return product;
}
Expand Down
6 changes: 6 additions & 0 deletions Week3/homework/step2-7.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ f2(y);
console.log(y);

// Add your explanation as a comment here
// In the first example, x is a global variable meaning that it can be accessed in and out of the function. When the
// value of x is passed in the function, the function adds one to it and returns a value of 10.

// In the second function, the value of y is an object containing a key and a value.
// when the object is passed in the function, one is added to the value of the object itself
// and the value of the value increases by 1 and we get {x: 10}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you get it (?). Another example:

let a = 4
let b = a
a += 1
What's the value of b?

vs objects...

let a = { name: 'gabe' }
b = a
a.country = 'us'
what's the value of b?

Do you see the difference?

4 changes: 3 additions & 1 deletion Week3/homework/step3-bonus.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c'];

function makeUnique(arr) {
// Replace this comment and the next line with your code
console.log(arr);
arr = new Set(arr);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice technique using Set data structure 👍

arr = Array.from(arr);
return arr;
}

const uniqueValues = makeUnique(values);
Expand Down
2 changes: 2 additions & 0 deletions Week3/homework/step3.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ console.log(addSix(10)); // returns 16
console.log(addSix(21)); // returns 27

// Do not change or remove anything below this line
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above, you'll need to add code to make createBase function work


// ***** need explanation
module.exports = createBase;
Loading