feat(curriculum): daily challenges 161-170 (#65140)

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Tom
2026-01-14 09:05:49 -06:00
committed by GitHub
parent bc040eed12
commit 5262205540
23 changed files with 1799 additions and 1 deletions
@@ -0,0 +1,93 @@
---
id: 694596b0585c11170ac7c7f9
title: "Challenge 161: Free Shipping"
challengeType: 28
dashedName: challenge-161
---
# --description--
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.
The given array will contain items from the list below:
| Item | Price |
| - | - |
| `"shirt"` | 34.25 |
| `"jeans"` | 48.50 |
| `"shoes"` | 75.00 |
| `"hat"` | 19.95 |
| `"socks"` | 15.00 |
| `"jacket"` | 109.95 |
# --hints--
`getsFreeShipping(["shoes"], 50)` should return `true`.
```js
assert.isTrue(getsFreeShipping(["shoes"], 50));
```
`getsFreeShipping(["hat", "socks"], 50)` should return `false`.
```js
assert.isFalse(getsFreeShipping(["hat", "socks"], 50));
```
`getsFreeShipping(["jeans", "shirt", "jacket"], 75)` should return `true`.
```js
assert.isTrue(getsFreeShipping(["jeans", "shirt", "jacket"], 75));
```
`getsFreeShipping(["socks", "socks", "hat"], 75)` should return `false`.
```js
assert.isFalse(getsFreeShipping(["socks", "socks", "hat"], 75));
```
`getsFreeShipping(["shirt", "shirt", "jeans", "socks"], 100)` should return `true`.
```js
assert.isTrue(getsFreeShipping(["shirt", "shirt", "jeans", "socks"], 100));
```
`getsFreeShipping(["hat", "socks", "hat", "jeans", "shoes", "hat"], 200)` should return `false`.
```js
assert.isFalse(getsFreeShipping(["hat", "socks", "hat", "jeans", "shoes", "hat"], 200));
```
# --seed--
## --seed-contents--
```js
function getsFreeShipping(cart, minimum) {
return cart;
}
```
# --solutions--
```js
function getsFreeShipping(cart, minimum) {
const prices = {
shirt: 34.25,
jeans: 48.50,
shoes: 75.00,
hat: 19.95,
socks: 15.00,
jacket: 109.95
};
let total = 0;
for (const item of cart) {
total += prices[item];
}
return total >= minimum;
}
```
@@ -0,0 +1,85 @@
---
id: 694596b0585c11170ac7c7fa
title: "Challenge 162: Energy Consumption"
challengeType: 28
dashedName: challenge-162
---
# --description--
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.
To compare them, convert both values to joules using the following conversions:
- 1 Calorie equals 4184 joules.
- 1 watt-hour equals 3600 joules.
Return:
- `"Workout"` if the workout used more energy.
- `"Devices"` if the device used more energy.
- `"Equal"` if both used the same amount of energy.
# --hints--
`compareEnergy(250, 50)` should return `"Workout"`.
```js
assert.equal(compareEnergy(250, 50), "Workout");
```
`compareEnergy(100, 200)` should return `"Devices"`.
```js
assert.equal(compareEnergy(100, 200), "Devices");
```
`compareEnergy(450, 523)` should return `"Equal"`.
```js
assert.equal(compareEnergy(450, 523), "Equal");
```
`compareEnergy(300, 75)` should return `"Workout"`.
```js
assert.equal(compareEnergy(300, 75), "Workout");
```
`compareEnergy(200, 250)` should return `"Devices"`.
```js
assert.equal(compareEnergy(200, 250), "Devices");
```
`compareEnergy(900, 1046)` should return `"Equal"`.
```js
assert.equal(compareEnergy(900, 1046), "Equal");
```
# --seed--
## --seed-contents--
```js
function compareEnergy(caloriesBurned, wattHoursUsed) {
return caloriesBurned;
}
```
# --solutions--
```js
function compareEnergy(caloriesBurned, wattHoursUsed) {
const workoutEnergy = caloriesBurned * 4184;
const deviceEnergy = wattHoursUsed * 3600;
console.log(workoutEnergy);
console.log(deviceEnergy);
if (workoutEnergy > deviceEnergy) return "Workout";
if (deviceEnergy > workoutEnergy) return "Devices";
return "Equal";
}
```
@@ -0,0 +1,76 @@
---
id: 694596b0585c11170ac7c7fb
title: "Challenge 163: Consonant Case"
challengeType: 28
dashedName: challenge-163
---
# --description--
Given a string representing a variable name, convert it to consonant case using the following rules:
- All consonants should be converted to uppercase.
- All vowels (`a`, `e`, `i`, `o`, `u` in any case) should be converted to lowercase.
- All hyphens (`-`) should be converted to underscores (`_`).
# --hints--
`toConsonantCase("helloworld")` should return `"HeLLoWoRLD"`.
```js
assert.equal(toConsonantCase("helloworld"), "HeLLoWoRLD");
```
`toConsonantCase("HELLOWORLD")` should return `"HeLLoWoRLD"`.
```js
assert.equal(toConsonantCase("HELLOWORLD"), "HeLLoWoRLD");
```
`toConsonantCase("_hElLO-WOrlD-")` should return `"_HeLLo_WoRLD_"`.
```js
assert.equal(toConsonantCase("_hElLO-WOrlD-"), "_HeLLo_WoRLD_");
```
`toConsonantCase("_~-generic_~-variable_~-name_~-here-~_")` should return `"_~_GeNeRiC_~_VaRiaBLe_~_NaMe_~_HeRe_~_"`.
```js
assert.equal(toConsonantCase("_~-generic_~-variable_~-name_~-here-~_"), "_~_GeNeRiC_~_VaRiaBLe_~_NaMe_~_HeRe_~_");
```
# --seed--
## --seed-contents--
```js
function toConsonantCase(str) {
return str;
}
```
# --solutions--
```js
function toConsonantCase(str) {
const vowels = "aeiouAEIOU";
let result = "";
for (let char of str) {
if (char === "-") {
result += "_";
} else if (/[a-zA-Z]/.test(char)) {
if (vowels.includes(char)) {
result += char.toLowerCase();
} else {
result += char.toUpperCase();
}
} else {
result += char;
}
}
return result;
}
```
@@ -0,0 +1,57 @@
---
id: 694596b0585c11170ac7c7fc
title: "Challenge 164: Markdown Inline Code Parser"
challengeType: 28
dashedName: challenge-164
---
# --description--
Given a string of Markdown that includes one or more inline code blocks, return the equivalent HTML string.
Inline code blocks in Markdown use a single backtick (``` ` ```) at the start and end of the code block text.
Return the given string with all code blocks converted to HTML `code` tags.
For example, given the string ```"Use `let` to declare the variable."```, return `"Use <code>let</code> to declare the variable."`.
Note: The console may not display HTML tags in strings when logging messages. Check the browser console to see logs with tags included.
# --hints--
```parseInlineCode("Use `let` to declare the variable.")``` should return `"Use <code>let</code> to declare the variable."`.
```js
assert.equal(parseInlineCode("Use `let` to declare the variable."), "Use <code>let</code> to declare the variable.");
```
```parseInlineCode("Use `let` or `const` to declare a variable.")``` should return `"Use <code>let</code> or <code>const</code> to declare a variable."`.
```js
assert.equal(parseInlineCode("Use `let` or `const` to declare a variable."), "Use <code>let</code> or <code>const</code> to declare a variable.");
```
```parseInlineCode("Run `npm install` then `npm start`.")``` should return `"Run <code>npm install</code> then <code>npm start</code>."`.
```js
assert.equal(parseInlineCode("Run `npm install` then `npm start`."), "Run <code>npm install</code> then <code>npm start</code>.");
```
# --seed--
## --seed-contents--
```js
function parseInlineCode(markdown) {
return markdown;
}
```
# --solutions--
```js
function parseInlineCode(markdown) {
return markdown.replace(/`([^`]+)`/g, "<code>$1</code>");
}
```
@@ -0,0 +1,104 @@
---
id: 694596b0585c11170ac7c7fd
title: "Challenge 165: Class Average"
challengeType: 28
dashedName: challenge-165
---
# --description--
Given an array of exam scores (numbers), return the average score in form of a letter grade according to the following chart:
| Average Score | Letter Grade |
| - | - |
| 97-100 | `"A+"` |
| 93-96 | `"A"` |
| 90-92 | `"A"` |
| 87-89 | `"B+"` |
| 83-86 | `"B"` |
| 80-82 | `"B-"` |
| 77-79 | `"C+"` |
| 7376 | `"C"` |
| 70-72 | `"C-"` |
| 67-69 | `"D+"` |
| 63-66 | `"D"` |
| 6062 | `"D-"` |
| below 60 | `"F"` |
Calculate the average by adding all scores in the array and dividing by the total number of scores.
# --hints--
`getAverageGrade([92, 91, 90, 94, 89, 93])` should return `"A-"`.
```js
assert.equal(getAverageGrade([92, 91, 90, 94, 89, 93]), "A-");
```
`getAverageGrade([84, 89, 85, 100, 91, 88, 79])` should return `"B+"`.
```js
assert.equal(getAverageGrade([84, 89, 85, 100, 91, 88, 79]), "B+");
```
`getAverageGrade([63, 69, 65, 66, 71, 64, 65])` should return `"D"`.
```js
assert.equal(getAverageGrade([63, 69, 65, 66, 71, 64, 65]), "D");
```
`getAverageGrade([97, 98, 99, 100, 96, 97, 98, 99, 100])` should return `"A+"`.
```js
assert.equal(getAverageGrade([97, 98, 99, 100, 96, 97, 98, 99, 100]), "A+");
```
`getAverageGrade([75, 100, 88, 79, 80, 78, 64, 60])` should return `"C+"`.
```js
assert.equal(getAverageGrade([75, 100, 88, 79, 80, 78, 64, 60]), "C+");
```
`getAverageGrade([45, 48, 50, 52, 100, 54, 56, 58, 59])` should return `"F"`.
```js
assert.equal(getAverageGrade([45, 48, 50, 52, 100, 54, 56, 58, 59]), "F");
```
# --seed--
## --seed-contents--
```js
function getAverageGrade(scores) {
return scores;
}
```
# --solutions--
```js
function getAverageGrade(scores) {
const avg =
scores.reduce((sum, score) => sum + score, 0) / scores.length;
if (avg >= 97) return "A+";
if (avg >= 93) return "A";
if (avg >= 90) return "A-";
if (avg >= 87) return "B+";
if (avg >= 83) return "B";
if (avg >= 80) return "B-";
if (avg >= 77) return "C+";
if (avg >= 73) return "C";
if (avg >= 70) return "C-";
if (avg >= 67) return "D+";
if (avg >= 63) return "D";
if (avg >= 60) return "D-";
return "F";
}
```
@@ -0,0 +1,95 @@
---
id: 696655d24b614176d4c9b789
title: "Challenge 166: Hex Validator"
challengeType: 28
dashedName: challenge-166
---
# --description--
Given a string, determine whether it is a valid CSS hex color. A valid CSS hex color must:
- Start with a `#`, and
- be followed by either 3 or 6 hexadecimal characters.
Hexadecimal characters are numbers `0` through `9` and letters `a` through `f` (case-insensitive).
# --hints--
`isValidHex("#123")` should return `true`.
```js
assert.isTrue(isValidHex("#123"));
```
`isValidHex("#123abc")` should return `true`.
```js
assert.isTrue(isValidHex("#123abc"));
```
`isValidHex("#ABCDEF")` should return `true`.
```js
assert.isTrue(isValidHex("#ABCDEF"));
```
`isValidHex("#0a1B2c")` should return `true`.
```js
assert.isTrue(isValidHex("#0a1B2c"));
```
`isValidHex("#12G")` should return `false`.
```js
assert.isFalse(isValidHex("#12G"));
```
`isValidHex("#1234567")` should return `false`.
```js
assert.isFalse(isValidHex("#1234567"));
```
`isValidHex("#12 3")` should return `false`.
```js
assert.isFalse(isValidHex("#12 3"));
```
`isValidHex("fff")` should return `false`.
```js
assert.isFalse(isValidHex("fff"));
```
# --seed--
## --seed-contents--
```js
function isValidHex(str) {
return str;
}
```
# --solutions--
```js
function isValidHex(str) {
if (str[0] !== "#") return false;
const hex = str.slice(1);
if (hex.length !== 3 && hex.length !== 6) return false;
for (let char of hex) {
if (!/[0-9a-fA-F]/.test(char)) {
return false;
}
}
return true;
}
```
@@ -0,0 +1,74 @@
---
id: 696655d24b614176d4c9b78a
title: "Challenge 167: Bingo! Letter"
challengeType: 28
dashedName: challenge-167
---
# --description--
Given a number, return the bingo letter associated with it (capitalized). Bingo numbers are grouped as follows:
| Letter | Number Range |
| - | - |
| `"B"` | 1-15 |
| `"I"` | 16-30 |
| `"N"` | 31-45 |
| `"G"` | 46-60 |
| `"O"` | 61-75 |
# --hints--
`getBingoLetter(75)` should return `"O"`.
```js
assert.equal(getBingoLetter(75), "O");
```
`getBingoLetter(54)` should return `"G"`.
```js
assert.equal(getBingoLetter(54), "G");
```
`getBingoLetter(25)` should return `"I"`.
```js
assert.equal(getBingoLetter(25), "I");
```
`getBingoLetter(38)` should return `"N"`.
```js
assert.equal(getBingoLetter(38), "N");
```
`getBingoLetter(11)` should return `"11"`.
```js
assert.equal(getBingoLetter(11), "B");
```
# --seed--
## --seed-contents--
```js
function getBingoLetter(n) {
return n;
}
```
# --solutions--
```js
function getBingoLetter(n) {
if (n >= 1 && n <= 15) return "B";
if (n >= 16 && n <= 30) return "I";
if (n >= 31 && n <= 45) return "N";
if (n >= 46 && n <= 60) return "G";
if (n >= 61 && n <= 75) return "O";
return null;
}
```
@@ -0,0 +1,65 @@
---
id: 696655d24b614176d4c9b78b
title: "Challenge 168: Scaled Image"
challengeType: 28
dashedName: challenge-168
---
# --description--
Given a string representing the width and height of an image, and a number to scale the image, return the scaled width and height.
- The input string is in the format `"WxH"`. For example, `"800x600"`.
- The scale is a number to multiply the width and height by.
Return the scaled dimensions in the same `"WxH"` format.
# --hints--
`scaleImage("800x600", 2)` should return `"1600x1200"`.
```js
assert.equal(scaleImage("800x600", 2), "1600x1200");
```
`scaleImage("100x100", 10)` should return `"1000x1000"`.
```js
assert.equal(scaleImage("100x100", 10), "1000x1000");
```
`scaleImage("1024x768", 0.5)` should return `"512x384"`.
```js
assert.equal(scaleImage("1024x768", 0.5), "512x384");
```
`scaleImage("300x200", 1.5)` should return `"450x300"`.
```js
assert.equal(scaleImage("300x200", 1.5), "450x300");
```
# --seed--
## --seed-contents--
```js
function scaleImage(size, scale) {
return size;
}
```
# --solutions--
```js
function scaleImage(size, scale) {
const [width, height] = size.split("x").map(Number);
const newWidth = width * scale;
const newHeight = height * scale;
return `${newWidth}x${newHeight}`;
}
```
@@ -0,0 +1,69 @@
---
id: 696655d24b614176d4c9b78c
title: "Challenge 169: FizzBuzz Mini"
challengeType: 28
dashedName: challenge-169
---
# --description--
Given an integer, return a string based on the following rules:
- If the number is divisible by 3, return `"Fizz"`.
- If the number is divisible by 5, return `"Buzz"`.
- If the number is divisible by both 3 and 5, return `"FizzBuzz"`.
- Otherwise, return the given number as a string.
# --hints--
`fizzBuzzMini(3)` should return `"Fizz"`.
```js
assert.equal(fizzBuzzMini(3), "Fizz");
```
`fizzBuzzMini(4)` should return `"4"`.
```js
assert.strictEqual(fizzBuzzMini(4), "4");
```
`fizzBuzzMini(35)` should return `"Buzz"`.
```js
assert.equal(fizzBuzzMini(35), "Buzz");
```
`fizzBuzzMini(75)` should return `"FizzBuzz"`.
```js
assert.equal(fizzBuzzMini(75), "FizzBuzz");
```
`fizzBuzzMini(98)` should return `"98"`.
```js
assert.strictEqual(fizzBuzzMini(98), "98");
```
# --seed--
## --seed-contents--
```js
function fizzBuzzMini(n) {
return n;
}
```
# --solutions--
```js
function fizzBuzzMini(n) {
if (n % 3 === 0 && n % 5 === 0) return "FizzBuzz";
if (n % 3 === 0) return "Fizz";
if (n % 5 === 0) return "Buzz";
return String(n);
}
```
@@ -0,0 +1,69 @@
---
id: 696655d24b614176d4c9b78d
title: "Challenge 170: Odd or Even Day"
challengeType: 28
dashedName: challenge-170
---
# --description--
Given a timestamp (number of milliseconds since the Unix epoch), return:
- `"odd"` if the day of the month for that timestamp is odd.
- `"even"` if the day of the month for that timestamp is even.
For example, given `1769472000000`, a timestamp for January 27th, 2026, return `"odd"` because the day number (`27`) is an odd number.
# --hints--
`oddOrEvenDay(1769472000000)` should return `"odd"`.
```js
assert.equal(oddOrEvenDay(1769472000000), "odd");
```
`oddOrEvenDay(1769444440000)` should return `"even"`.
```js
assert.equal(oddOrEvenDay(1769444440000), "even");
```
`oddOrEvenDay(6739456780000)` should return `"odd"`.
```js
assert.equal(oddOrEvenDay(6739456780000), "odd");
```
`oddOrEvenDay(1)` should return `"odd"`.
```js
assert.equal(oddOrEvenDay(1), "odd");
```
`oddOrEvenDay(86400000)` should return `"even"`.
```js
assert.equal(oddOrEvenDay(86400000), "even");
```
# --seed--
## --seed-contents--
```js
function oddOrEvenDay(timestamp) {
return timestamp;
}
```
# --solutions--
```js
function oddOrEvenDay(timestamp) {
const date = new Date(timestamp);
const day = date.getUTCDate();
return day % 2 === 0 ? "even" : "odd";
}
```
@@ -0,0 +1,108 @@
---
id: 694596b0585c11170ac7c7f9
title: "Challenge 161: Free Shipping"
challengeType: 29
dashedName: challenge-161
---
# --description--
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.
The given array will contain items from the list below:
| Item | Price |
| - | - |
| `"shirt"` | 34.25 |
| `"jeans"` | 48.50 |
| `"shoes"` | 75.00 |
| `"hat"` | 19.95 |
| `"socks"` | 15.00 |
| `"jacket"` | 109.95 |
# --hints--
`gets_free_shipping(["shoes"], 50)` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(gets_free_shipping(["shoes"], 50), True)`)
}})
```
`gets_free_shipping(["hat", "socks"], 50)` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(gets_free_shipping(["hat", "socks"], 50), False)`)
}})
```
`gets_free_shipping(["jeans", "shirt", "jacket"], 75)` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(gets_free_shipping(["jeans", "shirt", "jacket"], 75), True)`)
}})
```
`gets_free_shipping(["socks", "socks", "hat"], 75)` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(gets_free_shipping(["socks", "socks", "hat"], 75), False)`)
}})
```
`gets_free_shipping(["shirt", "shirt", "jeans", "socks"], 100)` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(gets_free_shipping(["shirt", "shirt", "jeans", "socks"], 100), True)`)
}})
```
`gets_free_shipping(["hat", "socks", "hat", "jeans", "shoes", "hat"], 200)` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(gets_free_shipping(["hat", "socks", "hat", "jeans", "shoes", "hat"], 200), False)`)
}})
```
# --seed--
## --seed-contents--
```py
def gets_free_shipping(cart, minimum):
return cart
```
# --solutions--
```py
def gets_free_shipping(cart, minimum):
prices = {
"shirt": 34.25,
"jeans": 48.50,
"shoes": 75.00,
"hat": 19.95,
"socks": 15.00,
"jacket": 109.95
}
total = 0
for item in cart:
total += prices[item]
return total >= minimum
```
@@ -0,0 +1,101 @@
---
id: 694596b0585c11170ac7c7fa
title: "Challenge 162: Energy Consumption"
challengeType: 29
dashedName: challenge-162
---
# --description--
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.
To compare them, convert both values to joules using the following conversions:
- 1 Calorie equals 4184 joules.
- 1 watt-hour equals 3600 joules.
Return:
- `"Workout"` if the workout used more energy.
- `"Devices"` if the device used more energy.
- `"Equal"` if both used the same amount of energy.
# --hints--
`compare_energy(250, 50)` should return `"Workout"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(compare_energy(250, 50), "Workout")`)
}})
```
`compare_energy(100, 200)` should return `"Devices"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(compare_energy(100, 200), "Devices")`)
}})
```
`compare_energy(450, 523)` should return `"Equal"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(compare_energy(450, 523), "Equal")`)
}})
```
`compare_energy(300, 75)` should return `"Workout"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(compare_energy(300, 75), "Workout")`)
}})
```
`compare_energy(200, 250)` should return `"Devices"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(compare_energy(200, 250), "Devices")`)
}})
```
`compare_energy(900, 1046)` should return `"Equal"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(compare_energy(900, 1046), "Equal")`)
}})
```
# --seed--
## --seed-contents--
```py
def compare_energy(calories_burned, watt_hours_used):
return calories_burned
```
# --solutions--
```py
def compare_energy(calories_burned, watt_hours_used):
workout_energy = calories_burned * 4184
device_energy = watt_hours_used * 3600
if workout_energy > device_energy:
return "Workout"
if device_energy > workout_energy:
return "Devices"
return "Equal"
```
@@ -0,0 +1,86 @@
---
id: 694596b0585c11170ac7c7fb
title: "Challenge 163: Consonant Case"
challengeType: 29
dashedName: challenge-163
---
# --description--
Given a string representing a variable name, convert it to consonant case using the following rules:
- All consonants should be converted to uppercase.
- All vowels (`a`, `e`, `i`, `o`, `u` in any case) should be converted to lowercase.
- All hyphens (`-`) should be converted to underscores (`_`).
# --hints--
`to_consonant_case("helloworld")` should return `"HeLLoWoRLD"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_consonant_case("helloworld"), "HeLLoWoRLD")`)
}})
```
`to_consonant_case("HELLOWORLD")` should return `"HeLLoWoRLD"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_consonant_case("HELLOWORLD"), "HeLLoWoRLD")`)
}})
```
`to_consonant_case("_hElLO-WOrlD-")` should return `"_HeLLo_WoRLD_"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_consonant_case("_hElLO-WOrlD-"), "_HeLLo_WoRLD_")`)
}})
```
`to_consonant_case("_~-generic_~-variable_~-name_~-here-~_")` should return `"_~_GeNeRiC_~_VaRiaBLe_~_NaMe_~_HeRe_~_"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_consonant_case("_~-generic_~-variable_~-name_~-here-~_"), "_~_GeNeRiC_~_VaRiaBLe_~_NaMe_~_HeRe_~_")`)
}})
```
# --seed--
## --seed-contents--
```py
def to_consonant_case(s):
return s
```
# --solutions--
```py
def to_consonant_case(s):
vowels = "aeiouAEIOU"
result = ""
for char in s:
if char == "-":
result += "_"
elif char.isalpha():
if char in vowels:
result += char.lower()
else:
result += char.upper()
else:
result += char
return result
```
@@ -0,0 +1,65 @@
---
id: 694596b0585c11170ac7c7fc
title: "Challenge 164: Markdown Inline Code Parser"
challengeType: 29
dashedName: challenge-164
---
# --description--
Given a string of Markdown that includes one or more inline code blocks, return the equivalent HTML string.
Inline code blocks in Markdown use a single backtick (``` ` ```) at the start and end of the code block text.
Return the given string with all code blocks converted to HTML `code` tags.
For example, given the string ```"Use `let` to declare the variable."```, return `"Use <code>let</code> to declare the variable."`.
Note: The console may not display HTML tags in strings when logging messages. Check the browser console to see logs with tags included.
# --hints--
```parse_inline_code("Use `let` to declare the variable.")``` should return `"Use <code>let</code> to declare the variable."`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(parse_inline_code("Use \`let\` to declare the variable."), "Use <code>let</code> to declare the variable.")`)
}})
```
```parse_inline_code("Use `let` or `const` to declare a variable.")``` should return `"Use <code>let</code> or <code>const</code> to declare a variable."`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(parse_inline_code("Use \`let\` or \`const\` to declare a variable."), "Use <code>let</code> or <code>const</code> to declare a variable.")`)
}})
```
```parse_inline_code("Run `npm install` then `npm start`.")``` should return `"Run <code>npm install</code> then <code>npm start</code>."`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(parse_inline_code("Run \`npm install\` then \`npm start\`."), "Run <code>npm install</code> then <code>npm start</code>.")`)
}})
```
# --seed--
## --seed-contents--
```py
def parse_inline_code(markdown):
return markdown
```
# --solutions--
```py
import re
def parse_inline_code(markdown):
return re.sub(r"`([^`]+)`", r"<code>\1</code>", markdown)
```
@@ -0,0 +1,119 @@
---
id: 694596b0585c11170ac7c7fd
title: "Challenge 165: Class Average"
challengeType: 29
dashedName: challenge-165
---
# --description--
Given an array of exam scores (numbers), return the average score in form of a letter grade according to the following chart:
| Average Score | Letter Grade |
| - | - |
| 97-100 | `"A+"` |
| 93-96 | `"A"` |
| 90-92 | `"A"` |
| 87-89 | `"B+"` |
| 83-86 | `"B"` |
| 80-82 | `"B-"` |
| 77-79 | `"C+"` |
| 7376 | `"C"` |
| 70-72 | `"C-"` |
| 67-69 | `"D+"` |
| 63-66 | `"D"` |
| 6062 | `"D-"` |
| below 60 | `"F"` |
Calculate the average by adding all scores in the array and dividing by the total number of scores.
# --hints--
`get_average_grade([92, 91, 90, 94, 89, 93])` should return `"A-"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_average_grade([92, 91, 90, 94, 89, 93]), "A-")`)
}})
```
`get_average_grade([84, 89, 85, 100, 91, 88, 79])` should return `"B+"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_average_grade([84, 89, 85, 100, 91, 88, 79]), "B+")`)
}})
```
`get_average_grade([63, 69, 65, 66, 71, 64, 65])` should return `"D"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_average_grade([63, 69, 65, 66, 71, 64, 65]), "D")`)
}})
```
`get_average_grade([97, 98, 99, 100, 96, 97, 98, 99, 100])` should return `"A+"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_average_grade([97, 98, 99, 100, 96, 97, 98, 99, 100]), "A+")`)
}})
```
`get_average_grade([75, 100, 88, 79, 80, 78, 64, 60])` should return `"C+"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_average_grade([75, 100, 88, 79, 80, 78, 64, 60]), "C+")`)
}})
```
`get_average_grade([45, 48, 50, 52, 100, 54, 56, 58, 59])` should return `"F"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_average_grade([45, 48, 50, 52, 100, 54, 56, 58, 59]), "F")`)
}})
```
# --seed--
## --seed-contents--
```py
def get_average_grade(scores):
return scores
```
# --solutions--
```py
def get_average_grade(scores):
avg = sum(scores) / len(scores)
if avg >= 97: return "A+"
if avg >= 93: return "A"
if avg >= 90: return "A-"
if avg >= 87: return "B+"
if avg >= 83: return "B"
if avg >= 80: return "B-"
if avg >= 77: return "C+"
if avg >= 73: return "C"
if avg >= 70: return "C-"
if avg >= 67: return "D+"
if avg >= 63: return "D"
if avg >= 60: return "D-"
return "F"
```
@@ -0,0 +1,117 @@
---
id: 696655d24b614176d4c9b789
title: "Challenge 166: Hex Validator"
challengeType: 29
dashedName: challenge-166
---
# --description--
Given a string, determine whether it is a valid CSS hex color. A valid CSS hex color must:
- Start with a `#`, and
- be followed by either 3 or 6 hexadecimal characters.
Hexadecimal characters are numbers `0` through `9` and letters `a` through `f` (case-insensitive).
# --hints--
`is_valid_hex("#123")` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_hex("#123"), True)`)
}})
```
`is_valid_hex("#123abc")` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_hex("#123abc"), True)`)
}})
```
`is_valid_hex("#ABCDEF")` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_hex("#ABCDEF"), True)`)
}})
```
`is_valid_hex("#0a1B2c")` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_hex("#0a1B2c"), True)`)
}})
```
`is_valid_hex("#12G")` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_hex("#12G"), False)`)
}})
```
`is_valid_hex("#1234567")` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_hex("#1234567"), False)`)
}})
```
`is_valid_hex("#12 3")` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_hex("#12 3"), False)`)
}})
```
`is_valid_hex("fff")` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_hex("fff"), False)`)
}})
```
# --seed--
## --seed-contents--
```py
def is_valid_hex(s):
return s
```
# --solutions--
```py
def is_valid_hex(s):
if not s.startswith("#"):
return False
hex_part = s[1:]
if len(hex_part) not in (3, 6):
return False
for char in hex_part:
if not char.lower() in "0123456789abcdef":
return False
return True
```
@@ -0,0 +1,92 @@
---
id: 696655d24b614176d4c9b78a
title: "Challenge 167: Bingo! Letter"
challengeType: 29
dashedName: challenge-167
---
# --description--
Given a number, return the bingo letter associated with it (capitalized). Bingo numbers are grouped as follows:
| Letter | Number Range |
| - | - |
| `"B"` | 1-15 |
| `"I"` | 16-30 |
| `"N"` | 31-45 |
| `"G"` | 46-60 |
| `"O"` | 61-75 |
# --hints--
`get_bingo_letter(75)` should return `"O"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_bingo_letter(75), "O")`)
}})
```
`get_bingo_letter(54)` should return `"G"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_bingo_letter(54), "G")`)
}})
```
`get_bingo_letter(25)` should return `"I"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_bingo_letter(25), "I")`)
}})
```
`get_bingo_letter(38)` should return `"N"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_bingo_letter(38), "N")`)
}})
```
`get_bingo_letter(11)` should return `"11"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_bingo_letter(11), "B")`)
}})
```
# --seed--
## --seed-contents--
```py
def get_bingo_letter(n):
return n
```
# --solutions--
```py
def get_bingo_letter(n):
if 1 <= n <= 15:
return "B"
if 16 <= n <= 30:
return "I"
if 31 <= n <= 45:
return "N"
if 46 <= n <= 60:
return "G"
if 61 <= n <= 75:
return "O"
return None
```
@@ -0,0 +1,75 @@
---
id: 696655d24b614176d4c9b78b
title: "Challenge 168: Scaled Image"
challengeType: 29
dashedName: challenge-168
---
# --description--
Given a string representing the width and height of an image, and a number to scale the image, return the scaled width and height.
- The input string is in the format `"WxH"`. For example, `"800x600"`.
- The scale is a number to multiply the width and height by.
Return the scaled dimensions in the same `"WxH"` format.
# --hints--
`scale_image("800x600", 2)` should return `"1600x1200"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(scale_image("800x600", 2), "1600x1200")`)
}})
```
`scale_image("100x100", 10)` should return `"1000x1000"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(scale_image("100x100", 10), "1000x1000")`)
}})
```
`scale_image("1024x768", 0.5)` should return `"512x384"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(scale_image("1024x768", 0.5), "512x384")`)
}})
```
`scale_image("300x200", 1.5)` should return `"450x300"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(scale_image("300x200", 1.5), "450x300")`)
}})
```
# --seed--
## --seed-contents--
```py
def scale_image(size, scale):
return size
```
# --solutions--
```py
def scale_image(size, scale):
width, height = map(int, size.split("x"))
new_width = round(width * scale)
new_height = round(height * scale)
return f"{new_width}x{new_height}"
```
@@ -0,0 +1,85 @@
---
id: 696655d24b614176d4c9b78c
title: "Challenge 169: FizzBuzz Mini"
challengeType: 29
dashedName: challenge-169
---
# --description--
Given an integer, return a string based on the following rules:
- If the number is divisible by 3, return `"Fizz"`.
- If the number is divisible by 5, return `"Buzz"`.
- If the number is divisible by both 3 and 5, return `"FizzBuzz"`.
- Otherwise, return the given number as a string.
# --hints--
`fizz_buzz_mini(3)` should return `"Fizz"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(fizz_buzz_mini(3), "Fizz")`)
}})
```
`fizz_buzz_mini(4)` should return `"4"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(fizz_buzz_mini(4), "4")`)
}})
```
`fizzBuzzMini(35)` should return `"Buzz"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(fizz_buzz_mini(35), "Buzz")`)
}})
```
`fizzBuzzMini(75)` should return `"FizzBuzz"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(fizz_buzz_mini(75), "FizzBuzz")`)
}})
```
`fizzBuzzMini(98)` should return `"98"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(fizz_buzz_mini(98), "98")`)
}})
```
# --seed--
## --seed-contents--
```py
def fizz_buzz_mini(n):
return n
```
# --solutions--
```py
def fizz_buzz_mini(n):
if n % 3 == 0 and n % 5 == 0:
return "FizzBuzz"
if n % 3 == 0:
return "Fizz"
if n % 5 == 0:
return "Buzz"
return str(n)
```
@@ -0,0 +1,83 @@
---
id: 696655d24b614176d4c9b78d
title: "Challenge 170: Odd or Even Day"
challengeType: 29
dashedName: challenge-170
---
# --description--
Given a timestamp (number of milliseconds since the Unix epoch), return:
- `"odd"` if the day of the month for that timestamp is odd.
- `"even"` if the day of the month for that timestamp is even.
For example, given `1769472000000`, a timestamp for January 27th, 2026, return `"odd"` because the day number (`27`) is an odd number.
# --hints--
`odd_or_even_day(1769472000000)` should return `"odd"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(odd_or_even_day(1769472000000), "odd")`)
}})
```
`odd_or_even_day(1769444440000)` should return `"even"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(odd_or_even_day(1769444440000), "even")`)
}})
```
`odd_or_even_day(6739456780000)` should return `"odd"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(odd_or_even_day(6739456780000), "odd")`)
}})
```
`odd_or_even_day(1)` should return `"odd"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(odd_or_even_day(1), "odd")`)
}})
```
`odd_or_even_day(86400000)` should return `"even"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(odd_or_even_day(86400000), "even")`)
}})
```
# --seed--
## --seed-contents--
```py
def odd_or_even_day(timestamp):
return timestamp
```
# --solutions--
```py
from datetime import datetime
def odd_or_even_day(timestamp):
dt = datetime.utcfromtimestamp(timestamp / 1000)
day = dt.day
return "even" if day % 2 == 0 else "odd"
```
@@ -646,6 +646,46 @@
{ {
"id": "6939b873185d8e00d453563f", "id": "6939b873185d8e00d453563f",
"title": "Challenge 160: Knight Moves" "title": "Challenge 160: Knight Moves"
},
{
"id": "694596b0585c11170ac7c7f9",
"title": "Challenge 161: Free Shipping"
},
{
"id": "694596b0585c11170ac7c7fa",
"title": "Challenge 162: Energy Consumption"
},
{
"id": "694596b0585c11170ac7c7fb",
"title": "Challenge 163: Consonant Case"
},
{
"id": "694596b0585c11170ac7c7fc",
"title": "Challenge 164: Markdown Inline Code Parser"
},
{
"id": "694596b0585c11170ac7c7fd",
"title": "Challenge 165: Class Average"
},
{
"id": "696655d24b614176d4c9b789",
"title": "Challenge 166: Hex Validator"
},
{
"id": "696655d24b614176d4c9b78a",
"title": "Challenge 167: Bingo! Letter"
},
{
"id": "696655d24b614176d4c9b78b",
"title": "Challenge 168: Scaled Image"
},
{
"id": "696655d24b614176d4c9b78c",
"title": "Challenge 169: FizzBuzz Mini"
},
{
"id": "696655d24b614176d4c9b78d",
"title": "Challenge 170: Odd or Even Day"
} }
] ]
} }
@@ -645,6 +645,46 @@
{ {
"id": "6939b873185d8e00d453563f", "id": "6939b873185d8e00d453563f",
"title": "Challenge 160: Knight Moves" "title": "Challenge 160: Knight Moves"
},
{
"id": "694596b0585c11170ac7c7f9",
"title": "Challenge 161: Free Shipping"
},
{
"id": "694596b0585c11170ac7c7fa",
"title": "Challenge 162: Energy Consumption"
},
{
"id": "694596b0585c11170ac7c7fb",
"title": "Challenge 163: Consonant Case"
},
{
"id": "694596b0585c11170ac7c7fc",
"title": "Challenge 164: Markdown Inline Code Parser"
},
{
"id": "694596b0585c11170ac7c7fd",
"title": "Challenge 165: Class Average"
},
{
"id": "696655d24b614176d4c9b789",
"title": "Challenge 166: Hex Validator"
},
{
"id": "696655d24b614176d4c9b78a",
"title": "Challenge 167: Bingo! Letter"
},
{
"id": "696655d24b614176d4c9b78b",
"title": "Challenge 168: Scaled Image"
},
{
"id": "696655d24b614176d4c9b78c",
"title": "Challenge 169: FizzBuzz Mini"
},
{
"id": "696655d24b614176d4c9b78d",
"title": "Challenge 170: Odd or Even Day"
} }
] ]
} }
@@ -13,7 +13,7 @@ const { MONGOHQ_URL } = process.env;
// Number challenges in the dev-playground blocks // Number challenges in the dev-playground blocks
// Update this if the number of challenges changes // Update this if the number of challenges changes
const EXPECTED_CHALLENGE_COUNT = 160; const EXPECTED_CHALLENGE_COUNT = 170;
// Date to set for the first challenge, second challenge will be one day later, etc... // Date to set for the first challenge, second challenge will be one day later, etc...
// **DO NOT CHANGE THIS AFTER RELEASE (if seeding production - okay for local dev)** // **DO NOT CHANGE THIS AFTER RELEASE (if seeding production - okay for local dev)**