Skip to content

Commit 5262205

Browse files
feat(curriculum): daily challenges 161-170 (freeCodeCamp#65140)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
1 parent bc040ee commit 5262205

23 files changed

Lines changed: 1799 additions & 1 deletion
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
id: 694596b0585c11170ac7c7f9
3+
title: "Challenge 161: Free Shipping"
4+
challengeType: 28
5+
dashedName: challenge-161
6+
---
7+
8+
# --description--
9+
10+
Given an array of strings representing items in your shopping cart, and a number for the minimum order amount to qualify for free shipping, determine if the items in your shopping cart qualify for free shipping.
11+
12+
The given array will contain items from the list below:
13+
14+
| Item | Price |
15+
| - | - |
16+
| `"shirt"` | 34.25 |
17+
| `"jeans"` | 48.50 |
18+
| `"shoes"` | 75.00 |
19+
| `"hat"` | 19.95 |
20+
| `"socks"` | 15.00 |
21+
| `"jacket"` | 109.95 |
22+
23+
# --hints--
24+
25+
`getsFreeShipping(["shoes"], 50)` should return `true`.
26+
27+
```js
28+
assert.isTrue(getsFreeShipping(["shoes"], 50));
29+
```
30+
31+
`getsFreeShipping(["hat", "socks"], 50)` should return `false`.
32+
33+
```js
34+
assert.isFalse(getsFreeShipping(["hat", "socks"], 50));
35+
```
36+
37+
`getsFreeShipping(["jeans", "shirt", "jacket"], 75)` should return `true`.
38+
39+
```js
40+
assert.isTrue(getsFreeShipping(["jeans", "shirt", "jacket"], 75));
41+
```
42+
43+
`getsFreeShipping(["socks", "socks", "hat"], 75)` should return `false`.
44+
45+
```js
46+
assert.isFalse(getsFreeShipping(["socks", "socks", "hat"], 75));
47+
```
48+
49+
`getsFreeShipping(["shirt", "shirt", "jeans", "socks"], 100)` should return `true`.
50+
51+
```js
52+
assert.isTrue(getsFreeShipping(["shirt", "shirt", "jeans", "socks"], 100));
53+
```
54+
55+
`getsFreeShipping(["hat", "socks", "hat", "jeans", "shoes", "hat"], 200)` should return `false`.
56+
57+
```js
58+
assert.isFalse(getsFreeShipping(["hat", "socks", "hat", "jeans", "shoes", "hat"], 200));
59+
```
60+
61+
# --seed--
62+
63+
## --seed-contents--
64+
65+
```js
66+
function getsFreeShipping(cart, minimum) {
67+
68+
return cart;
69+
}
70+
```
71+
72+
# --solutions--
73+
74+
```js
75+
function getsFreeShipping(cart, minimum) {
76+
const prices = {
77+
shirt: 34.25,
78+
jeans: 48.50,
79+
shoes: 75.00,
80+
hat: 19.95,
81+
socks: 15.00,
82+
jacket: 109.95
83+
};
84+
85+
let total = 0;
86+
87+
for (const item of cart) {
88+
total += prices[item];
89+
}
90+
91+
return total >= minimum;
92+
}
93+
```
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
id: 694596b0585c11170ac7c7fa
3+
title: "Challenge 162: Energy Consumption"
4+
challengeType: 28
5+
dashedName: challenge-162
6+
---
7+
8+
# --description--
9+
10+
Given the number of Calories burned during a workout, and the number of watt-hours used by your electronic devices during that workout, determine which one used more energy.
11+
12+
To compare them, convert both values to joules using the following conversions:
13+
14+
- 1 Calorie equals 4184 joules.
15+
- 1 watt-hour equals 3600 joules.
16+
17+
Return:
18+
19+
- `"Workout"` if the workout used more energy.
20+
- `"Devices"` if the device used more energy.
21+
- `"Equal"` if both used the same amount of energy.
22+
23+
# --hints--
24+
25+
`compareEnergy(250, 50)` should return `"Workout"`.
26+
27+
```js
28+
assert.equal(compareEnergy(250, 50), "Workout");
29+
```
30+
31+
`compareEnergy(100, 200)` should return `"Devices"`.
32+
33+
```js
34+
assert.equal(compareEnergy(100, 200), "Devices");
35+
```
36+
37+
`compareEnergy(450, 523)` should return `"Equal"`.
38+
39+
```js
40+
assert.equal(compareEnergy(450, 523), "Equal");
41+
```
42+
43+
`compareEnergy(300, 75)` should return `"Workout"`.
44+
45+
```js
46+
assert.equal(compareEnergy(300, 75), "Workout");
47+
```
48+
49+
`compareEnergy(200, 250)` should return `"Devices"`.
50+
51+
```js
52+
assert.equal(compareEnergy(200, 250), "Devices");
53+
```
54+
55+
`compareEnergy(900, 1046)` should return `"Equal"`.
56+
57+
```js
58+
assert.equal(compareEnergy(900, 1046), "Equal");
59+
```
60+
61+
# --seed--
62+
63+
## --seed-contents--
64+
65+
```js
66+
function compareEnergy(caloriesBurned, wattHoursUsed) {
67+
68+
return caloriesBurned;
69+
}
70+
```
71+
72+
# --solutions--
73+
74+
```js
75+
function compareEnergy(caloriesBurned, wattHoursUsed) {
76+
const workoutEnergy = caloriesBurned * 4184;
77+
const deviceEnergy = wattHoursUsed * 3600;
78+
79+
console.log(workoutEnergy);
80+
console.log(deviceEnergy);
81+
if (workoutEnergy > deviceEnergy) return "Workout";
82+
if (deviceEnergy > workoutEnergy) return "Devices";
83+
return "Equal";
84+
}
85+
```
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
id: 694596b0585c11170ac7c7fb
3+
title: "Challenge 163: Consonant Case"
4+
challengeType: 28
5+
dashedName: challenge-163
6+
---
7+
8+
# --description--
9+
10+
Given a string representing a variable name, convert it to consonant case using the following rules:
11+
12+
- All consonants should be converted to uppercase.
13+
- All vowels (`a`, `e`, `i`, `o`, `u` in any case) should be converted to lowercase.
14+
- All hyphens (`-`) should be converted to underscores (`_`).
15+
16+
# --hints--
17+
18+
`toConsonantCase("helloworld")` should return `"HeLLoWoRLD"`.
19+
20+
```js
21+
assert.equal(toConsonantCase("helloworld"), "HeLLoWoRLD");
22+
```
23+
24+
`toConsonantCase("HELLOWORLD")` should return `"HeLLoWoRLD"`.
25+
26+
```js
27+
assert.equal(toConsonantCase("HELLOWORLD"), "HeLLoWoRLD");
28+
```
29+
30+
`toConsonantCase("_hElLO-WOrlD-")` should return `"_HeLLo_WoRLD_"`.
31+
32+
```js
33+
assert.equal(toConsonantCase("_hElLO-WOrlD-"), "_HeLLo_WoRLD_");
34+
```
35+
36+
`toConsonantCase("_~-generic_~-variable_~-name_~-here-~_")` should return `"_~_GeNeRiC_~_VaRiaBLe_~_NaMe_~_HeRe_~_"`.
37+
38+
```js
39+
assert.equal(toConsonantCase("_~-generic_~-variable_~-name_~-here-~_"), "_~_GeNeRiC_~_VaRiaBLe_~_NaMe_~_HeRe_~_");
40+
```
41+
42+
# --seed--
43+
44+
## --seed-contents--
45+
46+
```js
47+
function toConsonantCase(str) {
48+
49+
return str;
50+
}
51+
```
52+
53+
# --solutions--
54+
55+
```js
56+
function toConsonantCase(str) {
57+
const vowels = "aeiouAEIOU";
58+
let result = "";
59+
60+
for (let char of str) {
61+
if (char === "-") {
62+
result += "_";
63+
} else if (/[a-zA-Z]/.test(char)) {
64+
if (vowels.includes(char)) {
65+
result += char.toLowerCase();
66+
} else {
67+
result += char.toUpperCase();
68+
}
69+
} else {
70+
result += char;
71+
}
72+
}
73+
74+
return result;
75+
}
76+
```
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
id: 694596b0585c11170ac7c7fc
3+
title: "Challenge 164: Markdown Inline Code Parser"
4+
challengeType: 28
5+
dashedName: challenge-164
6+
---
7+
8+
# --description--
9+
10+
Given a string of Markdown that includes one or more inline code blocks, return the equivalent HTML string.
11+
12+
Inline code blocks in Markdown use a single backtick (``` ` ```) at the start and end of the code block text.
13+
14+
Return the given string with all code blocks converted to HTML `code` tags.
15+
16+
For example, given the string ```"Use `let` to declare the variable."```, return `"Use <code>let</code> to declare the variable."`.
17+
18+
Note: The console may not display HTML tags in strings when logging messages. Check the browser console to see logs with tags included.
19+
20+
# --hints--
21+
22+
```parseInlineCode("Use `let` to declare the variable.")``` should return `"Use <code>let</code> to declare the variable."`.
23+
24+
```js
25+
assert.equal(parseInlineCode("Use `let` to declare the variable."), "Use <code>let</code> to declare the variable.");
26+
```
27+
28+
```parseInlineCode("Use `let` or `const` to declare a variable.")``` should return `"Use <code>let</code> or <code>const</code> to declare a variable."`.
29+
30+
```js
31+
assert.equal(parseInlineCode("Use `let` or `const` to declare a variable."), "Use <code>let</code> or <code>const</code> to declare a variable.");
32+
```
33+
34+
```parseInlineCode("Run `npm install` then `npm start`.")``` should return `"Run <code>npm install</code> then <code>npm start</code>."`.
35+
36+
```js
37+
assert.equal(parseInlineCode("Run `npm install` then `npm start`."), "Run <code>npm install</code> then <code>npm start</code>.");
38+
```
39+
40+
# --seed--
41+
42+
## --seed-contents--
43+
44+
```js
45+
function parseInlineCode(markdown) {
46+
47+
return markdown;
48+
}
49+
```
50+
51+
# --solutions--
52+
53+
```js
54+
function parseInlineCode(markdown) {
55+
return markdown.replace(/`([^`]+)`/g, "<code>$1</code>");
56+
}
57+
```

0 commit comments

Comments
 (0)