-
Notifications
You must be signed in to change notification settings - Fork 328
My homework Week3 #199
My homework Week3 #199
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
function foo(func) { | ||
// What to do here? | ||
return func | ||
} | ||
|
||
function bar() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,23 +3,38 @@ | |
// use a 'for' loop | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where did 2-step3.js go to? |
||
function repeatStringNumTimesWithFor(str, num) { | ||
// add your code here | ||
return str; | ||
let string = ""; | ||
for (let i = 0; i < num; i++) { | ||
string += str; | ||
} | ||
return string; | ||
} | ||
|
||
console.log('for', repeatStringNumTimesWithFor('abc', 3)); | ||
|
||
// use a 'while' loop | ||
function repeatStringNumTimesWithWhile(str, num) { | ||
// add your code here | ||
return str; | ||
while (num > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have to define string before you can use it.
|
||
string += str; | ||
num--; | ||
} | ||
return string; | ||
} | ||
|
||
console.log('while', repeatStringNumTimesWithWhile('abc', 3)); | ||
|
||
// use a 'do...while' loop | ||
function repeatStringNumTimesWithDoWhile(str, num) { | ||
// add your code here | ||
return str; | ||
/* this code is not working, i still | ||
struggling with do...while loop */ | ||
string = ''; | ||
do { | ||
string += str; | ||
num--; | ||
} while (num > n); | ||
return string; | ||
} | ||
|
||
console.log('while', repeatStringNumTimesWithDoWhile('abc', 3)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
'use strict'; | ||
// paste your freeCodeCamp solutions in here | ||
function Dog () { | ||
this.name = "Jumbo"; | ||
this.color = "Black"; | ||
this.numLegs = 4; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. ✅ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
'use strict'; | ||
// paste your freeCodeCamp solutions in here | ||
function Dog() { | ||
this.name = "Rupert"; | ||
this.color = "brown"; | ||
this.numLegs = 4; | ||
} | ||
// Add your code below this line | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This question was about nested loops, no the |
||
|
||
let hound = new Dog(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,14 @@ | |
const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I seem to be missing, |
||
|
||
// Add your function here. Try and come up with a good name for this function | ||
|
||
function removeDoubles(foo) { | ||
const uniqueLetters = []; | ||
for (let i = 0; i < foo.length; i++){ | ||
uniqueLetters.push(foo[i]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All you are doing here is copying the whole array. Not removing the duplicate values. |
||
} | ||
return uniqueLetters; | ||
} | ||
// Replace `yourFunction` with the name of the function you just created | ||
const uniqueValues = yourFunction(values); | ||
const uniqueValues = removeDoubles(values); | ||
|
||
console.log(uniqueValues); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite. All you will do here is return the function object. You want to call
func
and return the value from callingfunc
.