JavaScript Challenges
How Edabit Works
This is an introduction to how challenges on Edabit work. In the code editor below you'll see a starter function that looks like this: function hello() { } All you have to do is type return "hello edabit.com" between the curly braces { } and then click the Check button. If you did this correctly, a celebration window will pop up. Notes The returned stringReturn the Sum of Two Numbers
Create a function that takes two numbers as arguments and returns their sum. Examples addition(3, 2) ➞ 5 addition(-3, -6) ➞ -9 addition(7, 3) ➞ 10 Notes Don't forget to return the result. If you get stuck on a challenge, find help in the Resources tab. If you're really stuck, unlock solutions in the Solutions tab.Make It a Hashtag
Turn one word into a hashtag. Create makeHashtag to put "#" before word and return the new string. Keep the word just as it is. Examples makeHashtag("coding") // "#coding" makeHashtag("PixelArt") // "#PixelArt" makeHashtag("X") // "#X" Notes word contains 1 to 20 English letters, with no spaces or existing #. Do not change its capital letters.Name That Playlist
Give your playlist a name to match its mood. Create playlistName to return mood followed by " Mix". For "Late Night", return "Late Night Mix". Examples playlistName("Late Night") // "Late Night Mix" playlistName("Focus") // "Focus Mix" playlistName("Rainy Day") // "Rainy Day Mix" Notes mood is a nonempty string of at most 30 characters, with no spaces atPlayer Two Has Joined
Someone has joined your game! Create joinMessage to return their username followed by " has joined!". For "Nova", return "Nova has joined!". Examples joinMessage("Nova") // "Nova has joined!" joinMessage("Pixel7") // "Pixel7 has joined!" joinMessage("x") // "x has joined!" Notes username contains 1 to 20 English letters, digits or underscores. Keep it unOne More Encore
The crowd wants one more song! Create encoreTotal to return the total number of songs after the band adds one encore to songs. Examples encoreTotal(8) // 9 encoreTotal(0) // 1 encoreTotal(20) // 21 Notes songs is a whole number from 0 to 100. The encore always adds exactly one song.Convert Minutes into Seconds
Write a function that takes an integer minutes and converts it to seconds. Examples convert(5) ➞ 300 convert(3) ➞ 180 convert(2) ➞ 120 Notes Don't forget to return the result. If you get stuck on a challenge, find help in the Resources tab. If you're really stuck, unlock solutions in the Solutions tab.Return the Next Number from the Integer Passed
Create a function that takes a number as an argument, increments the number by +1 and returns the result. Examples addition(0) ➞ 1 addition(9) ➞ 10 addition(-3) ➞ -2 Notes Don't forget to return the result. If you get stuck on a challenge, find help in the Resources tab. If you're really stuck, unlock solutions in the Solutions tab.Area of a Triangle
Write a function that takes the base and height of a triangle and return its area. Examples triArea(3, 2) ➞ 3 triArea(7, 4) ➞ 14 triArea(10, 10) ➞ 50 Notes The area of a triangle is: (base * height) / 2 Don't forget to return the result. If you get stuck on a challenge, find help in the Resources tab. If you're really stuck, unlock solutions in the SolutioConvert Age to Days
Create a function that takes the age in years and returns the age in days. Examples calcAge(65) ➞ 23725 calcAge(0) ➞ 0 calcAge(20) ➞ 7300 Notes Use 365 days as the length of a year for this challenge. Ignore leap years and days between last birthday and now. Expect only non-negative integer inputs.Buggy Code (Part 1)
Fix the code in the code tab to pass this challenge (only syntax errors). Look at the examples below to get an idea of what the function should do. Examples cubes(3) ➞ 27 cubes(5) ➞ 125 cubes(10) ➞ 1000 Notes READ EVERY WORD CAREFULLY, CHARACTER BY CHARACTER! Don't overthink this challenge; it's not supposed to be hard.Open Your Loot Bag
What is at the top of your loot bag? Create firstLoot to return the first item in the loot array. Return its name, not the whole array. Examples firstLoot(["Potion","Gold","Ruby"]) // "Potion" firstLoot(["Map"]) // "Map" firstLoot(["Shield","Sword"]) // "Shield" Notes loot contains 1 to 5 item names in the order shown. Each name is a nonempty string of aPay the Blacksmith
The blacksmith has your new equipment ready. Create goldLeft to return how much gold you have left after paying price gold coins. Examples goldLeft(50, 20) // 30 goldLeft(25, 25) // 0 goldLeft(10, 0) // 10 Notes gold and price are whole numbers from 0 to 1000. You always have enough gold to pay. A free item costs 0.Feeding Time
It is feeding time at Jurassic Park. Each dinosaur in an enclosure gets portion kilograms of food. Create foodNeeded to return the total kilograms needed for dinosaurs dinosaurs. Examples foodNeeded(4, 6) // 24 foodNeeded(1, 12) // 12 foodNeeded(0, 10) // 0 Notes dinosaurs is a whole number from 0 to 20. portion is a whole number from 0 to 50. Every dinoPoints for Gryffindor!
Gryffindor has earned more house points! Create housePoints to add earned points to the current score and return the new score. Examples housePoints(120, 15) // 135 housePoints(0, 10) // 10 housePoints(50, 0) // 50 Notes score and earned are whole numbers from 0 to 1000. No points are taken away.Homer's Doughnuts
Homer has found the doughnut box. Create doughnutsLeft to return how many doughnuts remain after he eats eaten of the total doughnuts. Examples doughnutsLeft(12, 5) // 7 doughnutsLeft(6, 6) // 0 doughnutsLeft(8, 0) // 8 Notes total and eaten are whole numbers from 0 to 100. Homer never eats more doughnuts than there are.Coffee Supply
Plan your coffee supply. Create coffeeSupply to return the total number of cups you will need if you drink cupsPerDay cups each day for days days. Examples coffeeSupply(2, 5) // 10 coffeeSupply(1, 7) // 7 coffeeSupply(0, 10) // 0 Notes cupsPerDay is a whole number from 0 to 10. days is a whole number from 0 to 30. Return the total number of cups.Insert Coin
Ready to play? Each coin gives you two arcade credits. Create arcadeCredits to return how many credits you get from coins coins. Examples arcadeCredits(3) // 6 arcadeCredits(0) // 0 arcadeCredits(1) // 2 Notes coins is a whole number from 0 to 20. You start with no credits.Open the Loot Chest
A loot chest needs a certain number of keys. Create canOpenChest to return true if keys is at least needed, and false if you do not have enough. Examples canOpenChest(3, 2) // true canOpenChest(2, 2) // true canOpenChest(1, 2) // false Notes keys is a whole number from 0 to 100. needed is a whole number from 1 to 100. Return a boolean, not a message.Do Not Disturb
Toggle your Do Not Disturb setting. Create toggleDnd to return false when enabled is true, and true when enabled is false. Examples toggleDnd(true) // false toggleDnd(false) // true Notes enabled is a boolean. Return the opposite boolean, not a number or a message.