Challenges
JavaScript Challenges
The Foundations
1. Suuq Receipt
Faadumo runs a small shop. A customer buys rice for $12 and chicken for $18. Tax is 10%.
Calculate the full receipt:
- Subtotal, tax amount, and total
- Each on its own line
Example Output:
Rice: $12
Chicken: $18
Subtotal: $30
Tax (10%): $3
Total: $332. Salary
Bile worked 80 hours this month. His rate is 175 NOK per hour. Tax is 22%.
Calculate his earnings:
- Gross pay, tax, and net pay
- Each on its own line
Example Output:
Gross pay: 14000 NOK
Tax: 3080 NOK
Net pay: 10920 NOK3. Student Profile
Hodan just signed up for Bashi Academy. She is 22, lives in Oslo, and enrolled in JavaScript. She has paid. The course price never changes.
Store her full profile and print every detail:
- All six details
- Price cannot be reassigned
Example Output:
Name: Hodan
Age: 22
City: Oslo
Course: JavaScript
Paid: true
Price: $9.994. Data Inspector
A user just filled out a form. Before saving to the database you need to know the type of each value. Username: "Yusuf", age: 25, verified: true, score: null, phone: not filled yet.
Print each value with its type:
- Five values
- Value and type on each line
Example Output:
Yusuf - string
25 - number
true - boolean
null - object
undefined - undefined5. Flight Budget
Nimo wants to fly to Mogadishu. The ticket costs $620. Airport tax is $45. She has $950 saved.
Check if she can afford the trip:
- Total trip cost
- Whether she can afford it
- How much she has left or how much more she needs
Example Output:
Total cost: $665
She can afford it
Remaining: $2856. Parking Fee
Yusuf parked in Oslo for 4 hours. The garage charges 50 NOK for 1 hour or less, 100 NOK up to 3 hours, and 200 NOK after that.
Calculate what he pays:
- Hours parked
- Final fee based on the rules
Example Output:
Hours parked: 4
Parking fee: 200 NOK7. Xawaala Transfer
Ahmed is in Oslo sending $500 home. The exchange rate is 10 NOK per dollar. The fee is 4.5%.
Calculate what leaves his account:
- Amount in NOK
- Fee in NOK
- Total charged in NOK
- How much arrives in dollars
Example Output:
Amount: 5000 NOK
Fee: 225 NOK
Total charged: 5225 NOK
Arrives: $5008. Cinema Ticket
Ahmed is buying a cinema ticket in Oslo. He is 14 years old. The cinema charges 80 NOK for under 12, 100 NOK for 12 to 17, 130 NOK for 18 to 64, and 90 NOK for 65 and over.
Print the right ticket price:
- Age
- Price based on the rules
Example Output:
Age: 14
Ticket price: 100 NOK9. Grocery Run
Sahra goes to the supermarket with 500 NOK. She buys rice 85 NOK, chicken 120 NOK, bread 35 NOK, and milk 25 NOK.
Check if she has enough:
- Total cost
- Budget
- Change
Example Output:
Total: 265 NOK
Budget: 500 NOK
Change: 235 NOK10. Loan Eligibility
A bank approves loans based on three conditions: age at least 21, monthly income above 15000 NOK, and no existing debt. Applicant: age 24, income 18000 NOK, no debt.
Check all three conditions:
- Print approved or which condition failed
Example Output:
Loan approved11. Phone Plan
Amina is choosing a phone plan. Under 100 NOK: calls only. 100 to 300 NOK: calls and data. Above 300 NOK: calls, data, and streaming. She pays 250 NOK per month.
Print the right plan:
- Monthly cost
- What is included
Example Output:
Monthly cost: 250 NOK
Includes: calls and data12. Delivery Fee
Hodan orders food online. The order is 320 NOK. Delivery is free above 250 NOK. Below that it costs 49 NOK.
Check if she gets free delivery:
- Order amount
- Delivery fee
Example Output:
Order: 320 NOK
Delivery: free13. Gym Membership
Mahad wants to join a gym. Monthly fee is 399 NOK. He has 1200 NOK saved. He wants to know how many months he can afford and how much he has left.
Calculate his membership:
- Months he can afford
- Remaining balance
Example Output:
Months: 3
Remaining: 3 NOK14. Speed Check
Faarax is driving on a Norwegian highway. The speed limit is 90 km/h. He is driving at 112 km/h. The fine is 800 NOK for every 10 km/h over the limit.
Calculate the fine:
- How much over the limit
- Total fine
Example Output:
Over limit by: 22 km/h
Fine: 1600 NOK15. Course Progress
Abdullahi has completed 7 out of 18 lessons in the JavaScript course. Calculate his progress and print whether he is less than halfway, exactly halfway, or more than halfway.
Check his progress:
- Percentage completed
- Progress status
Example Output:
Progress: 38%
Status: less than halfwayThe Mechanics
16. Welcome Message
Yusuf builds a shop website. Every visitor gets a welcome message with their name.
Write the function and call it:
- A function that takes a name and prints a welcome message
- Call it with three different names
Example Output:
Welcome, Ahmed!
Welcome, Faadumo!
Welcome, Nimo!17. Currency Converter
Sahra needs to convert dollars to NOK. The rate is 10.
Write the function and test it:
- A function that takes a dollar amount and returns the NOK value
- Call it with 50, 200, and 500
Example Output:
$50 = 500 NOK
$200 = 2000 NOK
$500 = 5000 NOK18. Grade Report
Ahmed wants to know his letter grade. Score 90+ is A, 80-89 is B, 70-79 is C, 60-69 is D, below 60 is F.
Write the function and test it:
- A function that takes a name and score and returns a full report
- Call it with three students: Ahmed 85, Faadumo 92, Yusuf 54
Example Output:
Ahmed: 85 - B
Faadumo: 92 - A
Yusuf: 54 - F19. Discount Calculator
A shop gives different discounts based on membership. Gold: 20%, Silver: 10%, Basic: 5%.
Write the function and test it:
- A function that takes a price and membership level and returns the final price
- Call it with price 300 for each level
Example Output:
Gold: 240 NOK
Silver: 270 NOK
Basic: 285 NOK20. Contact List
Nimo has four contacts: "Ahmed", "Faadumo", "Yusuf", "Bile".
Store and read the list:
- Store all four in an array
- Print the first and last contact
- Print the total number of contacts
Example Output:
First: Ahmed
Last: Bile
Total: 421. Waiting List
A clinic has a waiting list: ["Hodan", "Mahad", "Sahra", "Bile", "Nimo"]. Hodan is called in. A new patient "Yusuf" arrives and gets priority.
Update the list:
- Remove the first person
- Add Yusuf to the front
- Print the updated list and its length
Example Output:
["Yusuf", "Mahad", "Sahra", "Bile", "Nimo"]
Length: 522. Cart Manager
Faadumo is shopping online. Her cart has ["rice", "eggs", "bread"]. She adds "chicken". She decides she does not need "eggs". Check if "bread" is still in the cart.
Update the cart:
- Add chicken to the end
- Remove eggs by position
- Check if bread is in the cart
- Print the final cart
Example Output:
["rice", "bread", "chicken"]
bread in cart: true23. Weekly Sales
A shop recorded daily sales: [1200, 980, 1450, 760, 1100, 890, 1300].
Calculate the results:
- Total sales for the week
- Average daily sales
Example Output:
Total: 7680 NOK
Average: 1097 NOK24. Passing Students
Ten students took an exam: [88, 45, 72, 91, 55, 68, 79, 43, 95, 61]. Passing score is 60.
Loop through and count:
- How many passed
- How many failed
Example Output:
Passed: 7
Failed: 325. Price Filter
A shop has these prices: [299, 149, 499, 89, 349, 199]. Everything above 200 NOK gets a 20% discount.
Loop through and print:
- Original price and discounted price for qualifying items
- Original price for items that do not qualify
Example Output:
299 -> 239 NOK
149 -> no discount
499 -> 399 NOK
89 -> no discount
349 -> 279 NOK
199 -> no discount26. Student Profile
Bile just enrolled. Name: "Bile", age: 19, city: "Hargeisa", course: "JavaScript", paid: true.
Store and update his profile:
- Store all five values in an object
- He moves to Oslo — update his city
- Print every detail
Example Output:
Name: Bile
Age: 19
City: Oslo
Course: JavaScript
Paid: true27. Product Stock
A shop has a laptop in stock. Name: "Laptop", price: 8999 NOK, stock: 5. A customer buys 2.
Update and check the stock:
- Update the stock after the purchase
- Check if stock is still available
- Print the result
Example Output:
Remaining stock: 3
Status: In stock28. Class Results
Five students submitted their scores. Ahmed 85, Faadumo 62, Yusuf 91, Nimo 47, Bile 78. Passing score is 60.
Loop through and report:
- Each student with pass or fail
- Total number of students who passed
Example Output:
Ahmed: Pass
Faadumo: Pass
Yusuf: Pass
Nimo: Fail
Bile: Pass
Passed: 429. Transaction History
Five customers sent money. Ahmed $200, Faadumo $450, Yusuf $120, Nimo $890, Bile $340.
Loop through and calculate:
- Print each transaction
- Total amount sent
- Largest transaction
Example Output:
Ahmed: $200
Faadumo: $450
Yusuf: $120
Nimo: $890
Bile: $340
Total: $2000
Largest: Nimo - $89030. Leaderboard
Five players finished a game. Mohamed 1200, Sagal 950, Ali 1500, Nimo 880, Hassan 1340.
Build the leaderboard:
- Print all players with their points
- Find the winner
- Calculate the average score
- Print how many players are above average
Example Output:
Mohamed: 1200
Sagal: 950
Ali: 1500
Nimo: 880
Hassan: 1340
Winner: Ali with 1500 points
Average: 1174 points
Above average: 3 playersThe Transformations
31. Transfer Check
Ahmed wants to send $800. His balance is $750.
Use one line to print the result:
- Approved or declined based on his balance
Example Output:
Transfer declined32. Membership Status
Hodan has 1200 points. Premium requires 1000 points.
Use one line to print her status:
Example Output:
Premium member33. Order Details
An order comes in from the system.
let order = { customer: "Faadumo", amount: 450, city: "Oslo", status: "pending" };Print all four values on separate lines without using dot notation:
Example Output:
Faadumo
450
Oslo
pending34. Student Card
A student profile arrives from the database.
let student = { name: "Yusuf", age: 21, course: "JavaScript", paid: true };Print a formatted student card in one line without using dot notation:
Example Output:
Yusuf, 21 — JavaScript — Paid: true35. Top Three
The final scores are in.
let scores = [95, 88, 76, 61, 45];Print first place, second place, and the rest without using index notation:
Example Output:
1st: 95
2nd: 88
Rest: [76, 61, 45]36. Cities
A user has lived in multiple cities.
let cities = ["Mogadishu", "Nairobi", "Oslo", "London"];Print the first city and all remaining cities without using index notation:
Example Output:
Born in: Mogadishu
Also lived in: ["Nairobi", "Oslo", "London"]37. Fee Calculator
Write a single-line function called calcFee that takes an amount and returns 4.5% of it.
Call it with 500, 1000, and 2000:
Example Output:
22.5
45
9038. Full Name
Write a single-line function called fullName that takes a first and last name and returns them combined.
Call it with three names:
Example Output:
Ahmed Maxamed
Faadumo Warsame
Yusuf Ali39. Process Payment
Write a function called processPayment that takes an amount and a callback. It prints "Processing..." then calls the callback with the amount.
Call it with a function that prints the confirmation:
Example Output:
Processing...
Payment of 500 NOK confirmed40. Notify User
Write a function called sendNotification that takes a username and a callback. Call it with "Ahmed" and a function that prints a welcome notification.
Example Output:
Notification sent to Ahmed
Welcome to Bashi Academy, Ahmed!41. Class Roster
let students = ["Ahmed", "Faadumo", "Yusuf", "Nimo", "Bile"];Print each student with their number. Do not use a for loop:
Example Output:
1. Ahmed
2. Faadumo
3. Yusuf
4. Nimo
5. Bile42. Sale Prices
A shop is running a 20% sale.
let prices = [100, 250, 80, 400, 150];Return a new array with all prices discounted. Do not use a for loop:
Example Output:
[80, 200, 64, 320, 120]43. Score Board
let students = [
{ name: "Ahmed", score: 85 },
{ name: "Faadumo", score: 72 },
{ name: "Yusuf", score: 91 },
{ name: "Nimo", score: 55 }
];Return a new array of formatted strings. Do not use a for loop:
Example Output:
["Ahmed: 85", "Faadumo: 72", "Yusuf: 91", "Nimo: 55"]44. High Earners
let salaries = [18000, 42000, 31000, 55000, 22000, 48000];Return only salaries above 35000 NOK. Do not use a for loop:
Example Output:
[42000, 55000, 48000]45. Oslo Students
let students = [
{ name: "Ahmed", city: "Oslo" },
{ name: "Faadumo", city: "Mogadishu" },
{ name: "Yusuf", city: "Oslo" },
{ name: "Nimo", city: "Hargeisa" },
{ name: "Bile", city: "Oslo" }
];Return only students in Oslo and print their names. Do not use a for loop:
Example Output:
Ahmed
Yusuf
Bile46. Order Lookup
You know filter and find. Use both here — not a loop.
let orders = [
{ id: 101, customer: "Sahra", status: "pending" },
{ id: 102, customer: "Mahad", status: "delivered" },
{ id: 103, customer: "Hodan", status: "pending" }
];Find all pending orders. Then find the first delivered one. Print both results:
Example Output:
Pending: Sahra, Hodan
First delivered: Mahad47. Failed and Passed
Two calls to filter is all you need. No loops, no if statements outside of the callback.
let students = [
{ name: "Ahmed", score: 85 },
{ name: "Faadumo", score: 45 },
{ name: "Yusuf", score: 91 },
{ name: "Nimo", score: 38 }
];Separate students into passed and failed. Print both groups and the count of each:
Example Output:
Passed: Ahmed, Yusuf (2)
Failed: Faadumo, Nimo (2)48. Ranked Leaderboard
Sort first, then use forEach to print. Calculate the average before you loop.
let players = [
{ name: "Mohamed", points: 1200 },
{ name: "Sagal", points: 950 },
{ name: "Ali", points: 1500 },
{ name: "Nimo", points: 880 }
];Sort by points highest to lowest. Print each player with their rank, points, and whether they are above the average:
Example Output:
1. Ali — 1500 — above average
2. Mohamed — 1200 — above average
3. Sagal — 950 — below average
4. Nimo — 880 — below average49. City Report
Sort first, then use map to add numbers. Do not use a for loop anywhere.
let cities = ["Oslo", "Mogadishu", "Hargeisa", "Nairobi", "London"];Sort alphabetically. Add a number to each city. Print the numbered list and the total count:
Example Output:
1. Hargeisa
2. London
3. Mogadishu
4. Nairobi
5. Oslo
Total: 5 cities50. Full Pipeline
Three methods chained together. No for loop anywhere.
let students = [
{ name: "Ahmed", score: 85 },
{ name: "Faadumo", score: 45 },
{ name: "Yusuf", score: 91 },
{ name: "Nimo", score: 38 },
{ name: "Bile", score: 72 }
];In one chain:
- Keep only students who passed (60 or above)
- Sort them from highest to lowest
- Print each with their rank and score
Example Output:
1. Yusuf — 91
2. Ahmed — 85
3. Bile — 72