Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Commit 63197b7

Browse files
committed
solving the mandatory function
1 parent 2f210fe commit 63197b7

3 files changed

Lines changed: 39 additions & 9 deletions

File tree

‎week-2/2-mandatory/2-function-creation.js‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ Tip: use logical operators
2525

2626
function validate(num) {
2727

28-
if (num <= 100)
29-
{
30-
num = true;
28+
if (num <=100 && typeof num === "number" && num % 2 == 0)
29+
{
30+
return true;
3131
}
3232
else {
33-
num =false;
33+
return false;
3434
}
3535
}
36-
validate(20);
36+
console.log(validate(20));
3737

3838

3939
/*
@@ -42,7 +42,11 @@ The function must NOT change the original array, arr.
4242
*/
4343

4444
function remove(arr, index) {
45-
return; // complete this statement
45+
if (arr.length > index) {
46+
return arr;
47+
}
48+
49+
// complete this statement
4650
}
4751

4852

@@ -54,7 +58,11 @@ Write a function that:
5458
- numbers greater 100 must be replaced with 100
5559
*/
5660

57-
function formatPercentage(arr) {}
61+
function formatPercentage(arr) {
62+
63+
64+
65+
}
5866

5967

6068

‎week-2/2-mandatory/3-playing-computer.js‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,24 @@
88
99
1. This program throws an error. Why? (If you can't find it, try executing it).
1010
2. Remove the line that throws the error.
11+
// The error was console.log(b);
1112
3. What is printed to the console?
13+
// 2
14+
6
15+
4
16+
9
17+
6
18+
13
19+
8
1220
4. How many times is "f1" called?
21+
// f1 called three times.
1322
5. How many times is "f2" called?
23+
//f2 called four times.
1424
6. What value does the "a" parameter take in the first "f1" call?
25+
"a" is equal to 6 ;
26+
1527
7. What is the value of the "a" outer variable when "f1" is called for the first time?
28+
"a" is equal to 7 ;
1629
*/
1730

1831
let x = 2;
@@ -28,7 +41,7 @@ const f2 = function(a, b) {
2841

2942
console.log(x);
3043
console.log(a);
31-
console.log(b);
44+
3245

3346
for (let i = 0; i < 5; ++i) {
3447
a = a + 1;

‎week-3/3-extra/3-sorting-algorithm.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ You don't have to worry about making this algorithm work fast! The idea is to ge
1414
"think" like a computer and practice your knowledge of basic JavaScript.
1515
*/
1616

17-
function sortAges(arr) {}
17+
function sortAges(arr) {
18+
19+
20+
21+
}
22+
23+
24+
25+
26+
1827

1928
/* ======= TESTS - DO NOT MODIFY ===== */
2029

0 commit comments

Comments
 (0)