-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchapter-3.js
More file actions
51 lines (41 loc) · 1021 Bytes
/
chapter-3.js
File metadata and controls
51 lines (41 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function min(a, b) {
if (a < b) return a;
else return b;
}
console.log(min(0, 10));
// → 0
console.log(min(0, -10));
// → -10
//TASK 2 - Recursion --- apparently it is not :)
function isEven(number) {
if (number % 2 == 0) {
return true;
} else return false;
}
console.log(isEven(50));
// → true
console.log(isEven(75));
// → false
console.log(isEven(-1));
// → ??
//TASK 3 - Bean counting
function countBs(word) {
let wordString = String(word);
let letterUpcase = 0;
for (let count = 0; count < wordString.length; count++){
if(wordString[count] === wordString[count].toUpperCase()){
letterUpcase++;
}
}
return letterUpcase;
}
function countChar(word, letter) {
let wordString = String(word);
let letterRepeat = 0;
for (let count = 0; count < wordString.length; count++){
if(wordString[count] === letter){
letterRepeat++;
}
}
return letterRepeat;
}