Skip to content

Commit 6e01904

Browse files
feat(curriculum): daily challenges 63-79 (freeCodeCamp#62367)
Co-authored-by: Ilenia <[email protected]>
1 parent f55140c commit 6e01904

39 files changed

+3027
-7
lines changed

curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68b06e589bf2273243814771.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ dashedName: challenge-36
99

1010
Given the current temperature of a room and a target temperature, return a string indicating how to adjust the room temperature based on these constraints:
1111

12-
- Return "heat" if the current temperature is below the target.
13-
- Return "cool" if the current temperature is above the target.
14-
- Return "hold" if the current temperature is equal to the target.
12+
- Return `"heat"` if the current temperature is below the target.
13+
- Return `"cool"` if the current temperature is above the target.
14+
- Return `"hold"` if the current temperature is equal to the target.
1515

1616
# --hints--
1717

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
id: 68cae5b538ff798bbd4da001
3+
title: "Challenge 63: Battle of Words"
4+
challengeType: 28
5+
dashedName: challenge-63
6+
---
7+
8+
# --description--
9+
10+
Given two sentences representing your team and an opposing team, where each word from your team battles the corresponding word from the opposing team, determine which team wins using the following rules:
11+
12+
- The given sentences will always contain the same number of words.
13+
- Words are separated by a single space and will only contain letters.
14+
- The value of each word is the sum of its letters.
15+
- Letters `a` to `z` correspond to the values `1` through `26`. For example, `a` is `1`, and `z` is `26`.
16+
- A capital letter doubles the value of the letter. For example, `A` is `2`, and `Z` is `52`.
17+
- Words battle in order: the first word of your team battles the first word of the opposing team, and so on.
18+
- A word wins if its value is greater than the opposing word's value.
19+
- The team with more winning words is the winner.
20+
21+
Return `"We win"` if your team is the winner, `"We lose"` if your team loses, and `"Draw"` if both teams have the same number of wins.
22+
23+
# --hints--
24+
25+
`battle("hello world", "hello word")` should return `"We win"`.
26+
27+
```js
28+
assert.equal(battle("hello world", "hello word"), "We win");
29+
```
30+
31+
`battle("Hello world", "hello world")` should return `"We win"`.
32+
33+
```js
34+
assert.equal(battle("Hello world", "hello world"), "We win");
35+
```
36+
37+
`battle("lorem ipsum", "kitty ipsum")` should return `"We lose"`.
38+
39+
```js
40+
assert.equal(battle("lorem ipsum", "kitty ipsum"), "We lose");
41+
```
42+
43+
`battle("hello world", "world hello")` should return `"Draw"`.
44+
45+
```js
46+
assert.equal(battle("hello world", "world hello"), "Draw");
47+
```
48+
49+
`battle("git checkout", "git switch")` should return `"We win"`.
50+
51+
```js
52+
assert.equal(battle("git checkout", "git switch"), "We win");
53+
```
54+
55+
`battle("Cheeseburger with fries", "Cheeseburger with Fries")` should return `"We lose"`.
56+
57+
```js
58+
assert.equal(battle("Cheeseburger with fries", "Cheeseburger with Fries"), "We lose");
59+
```
60+
61+
`battle("We must never surrender", "Our team must win")` should return `"Draw"`.
62+
63+
```js
64+
assert.equal(battle("We must never surrender", "Our team must win"), "Draw");
65+
```
66+
67+
# --seed--
68+
69+
## --seed-contents--
70+
71+
```js
72+
function battle(ourTeam, opponent) {
73+
74+
return ourTeam;
75+
}
76+
```
77+
78+
# --solutions--
79+
80+
```js
81+
function getCharacterValue(char) {
82+
const lowerCaseValue = char.toLowerCase().charCodeAt(0) - 96;
83+
return char >= 'A' && char <= 'Z' ? lowerCaseValue * 2 : lowerCaseValue;
84+
}
85+
86+
function getWordValue(word) {
87+
let wordValue = 0;
88+
for (let i=0; i<word.length; i++) {
89+
wordValue += getCharacterValue(word[i])
90+
}
91+
92+
return wordValue;
93+
}
94+
95+
function battle(ourTeam, opponent) {
96+
const myWords = ourTeam.split(' ');
97+
const opponentWords = opponent.split(' ');
98+
99+
let myWins = 0, opponentWins = 0;
100+
101+
for (let i=0; i<myWords.length; i++) {
102+
const myWordValue = getWordValue(myWords[i]);
103+
const opponentWordValue = getWordValue(opponentWords[i])
104+
105+
if (myWordValue > opponentWordValue) myWins++;
106+
if (opponentWordValue > myWordValue) opponentWins++;
107+
}
108+
109+
if (myWins > opponentWins) return 'We win';
110+
if (opponentWins > myWins) return 'We lose';
111+
return 'Draw';
112+
}
113+
```
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
id: 68cae5b538ff798bbd4da002
3+
title: "Challenge 64: 24 to 12"
4+
challengeType: 28
5+
dashedName: challenge-64
6+
---
7+
8+
# --description--
9+
10+
Given a string representing a time of the day in the 24-hour format of `"HHMM"`, return the time in its equivalent 12-hour format of `"H:MM AM"` or `"H:MM PM"`.
11+
12+
- The given input will always be a four-digit string in 24-hour time format, from `"0000"` to `"2359"`.
13+
14+
# --hints--
15+
16+
`to12("1124")` should return `"11:24 AM"`.
17+
18+
```js
19+
assert.equal(to12("1124"), "11:24 AM");
20+
```
21+
22+
`to12("0900")` should return `"9:00 AM"`.
23+
24+
```js
25+
assert.equal(to12("0900"), "9:00 AM");
26+
```
27+
28+
`to12("1455")` should return `"2:55 PM"`.
29+
30+
```js
31+
assert.equal(to12("1455"), "2:55 PM");
32+
```
33+
34+
`to12("2346")` should return `"11:46 PM"`.
35+
36+
```js
37+
assert.equal(to12("2346"), "11:46 PM");
38+
```
39+
40+
`to12("0030")` should return `"12:30 AM"`.
41+
42+
```js
43+
assert.equal(to12("0030"), "12:30 AM");
44+
```
45+
46+
# --seed--
47+
48+
## --seed-contents--
49+
50+
```js
51+
function to12(time) {
52+
53+
return time;
54+
}
55+
```
56+
57+
# --solutions--
58+
59+
```js
60+
function convertHours(hours) {
61+
if (hours === 0) return 12;
62+
if (hours > 12) return hours - 12;
63+
return hours;
64+
}
65+
66+
function to12(time) {
67+
const hours = parseInt(time.slice(0, 2), 10);
68+
const minutes = time.slice(2);
69+
const period = hours < 12 ? 'AM' : 'PM';
70+
71+
return `${convertHours(hours)}:${minutes} ${period}`;
72+
}
73+
```
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
id: 68cae5b538ff798bbd4da003
3+
title: "Challenge 65: String Count"
4+
challengeType: 28
5+
dashedName: challenge-65
6+
---
7+
8+
# --description--
9+
10+
Given two strings, determine how many times the second string appears in the first.
11+
12+
- The pattern string can overlap in the first string. For example, `"aaa"` contains `"aa"` twice. The first two `a`'s and the second two.
13+
14+
# --hints--
15+
16+
`count('abcdefg', 'def')` should return `1`.
17+
18+
```js
19+
assert.equal(count('abcdefg', 'def'), 1);
20+
```
21+
22+
`count('hello', 'world')` should return `0`.
23+
24+
```js
25+
assert.equal(count('hello', 'world'), 0);
26+
```
27+
28+
`count('mississippi', 'iss')` should return `2`.
29+
30+
```js
31+
assert.equal(count('mississippi', 'iss'), 2);
32+
```
33+
34+
`count('she sells seashells by the seashore', 'sh')` should return `3`.
35+
36+
```js
37+
assert.equal(count('she sells seashells by the seashore', 'sh'), 3);
38+
```
39+
40+
`count('101010101010101010101', '101')` should return `10`.
41+
42+
```js
43+
assert.equal(count('101010101010101010101', '101'), 10);
44+
```
45+
46+
# --seed--
47+
48+
## --seed-contents--
49+
50+
```js
51+
function count(text, pattern) {
52+
53+
return text;
54+
}
55+
```
56+
57+
# --solutions--
58+
59+
```js
60+
function count(text, pattern) {
61+
let occurrences = 0;
62+
63+
for (let i = 0; i <= text.length - pattern.length; i++) {
64+
if (text.slice(i, i + pattern.length) === pattern) {
65+
occurrences++;
66+
}
67+
}
68+
69+
return occurrences;
70+
}
71+
```
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
id: 68cae5b538ff798bbd4da004
3+
title: "Challenge 66: HTML Tag Stripper"
4+
challengeType: 28
5+
dashedName: challenge-66
6+
---
7+
8+
# --description--
9+
10+
Given a string of HTML code, remove the tags and return the plain text content.
11+
12+
- The input string will contain only valid HTML.
13+
- HTML tags may be nested.
14+
- Remove the tags and any attributes.
15+
16+
For example, `'<a href="#">Click here</a>'` should return `"Click here"`.
17+
18+
# --hints--
19+
20+
`stripTags('<a href="#">Click here</a>')` should return `"Click here"`.
21+
22+
```js
23+
assert.equal(stripTags('<a href="#">Click here</a>'), "Click here");
24+
```
25+
26+
`stripTags('<p class="center">Hello <b>World</b>!</p>')` should return `"Hello World!"`.
27+
28+
```js
29+
assert.equal(stripTags('<p class="center">Hello <b>World</b>!</p>'), "Hello World!");
30+
```
31+
32+
`stripTags('<img src="cat.jpg" alt="Cat">')` should return an empty string (`""`).
33+
34+
```js
35+
assert.equal(stripTags('<img src="cat.jpg" alt="Cat">'), "");
36+
```
37+
38+
`stripTags('<main id="main"><section class="section">section</section><section class="section">section</section></main>')` should return `sectionsection`.
39+
40+
```js
41+
assert.equal(stripTags('<main id="main"><section class="section">section</section><section class="section">section</section></main>'), "sectionsection");
42+
```
43+
44+
# --seed--
45+
46+
## --seed-contents--
47+
48+
```js
49+
function stripTags(html) {
50+
51+
return html;
52+
}
53+
```
54+
55+
# --solutions--
56+
57+
```js
58+
function stripTags(html) {
59+
return html.replace(/<[^>]*>/g, '');
60+
}
61+
```

0 commit comments

Comments
 (0)