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.Will the Next File Fit?
A drive has capacity megabytes of space, and used megabytes are already taken. Create fileFits to return true if a file of size megabytes will fit. Otherwise, return false. Filling the drive exactly is allowed. Examples fileFits(100, 70, 20) // true fileFits(100, 70, 31) // false fileFits(100, 70, 30) // true Notes All three numbers are whole numbers froRetry or Stop?
Create shouldRetry to decide whether to try a request again. Return true only when the previous attempt failed and attempts is less than limit. Otherwise, return false. Examples shouldRetry(true, 2, 3) // true shouldRetry(false, 2, 3) // false shouldRetry(true, 3, 3) // false Notes failed is a boolean. attempts is the number of attempts already made, froConvert 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.Keep the Newer Update
Two updates are written as [timestamp, value]. A larger timestamp means a newer update. Create newerValue to return the newer update's value, not its timestamp. If the timestamps match, return the first update's value. Examples newerValue([10,"ready"], [12,"busy"]) // "busy" newerValue([20,"online"], [15,"offline"]) // "online" newerValue([5,"first"], [5,"Spaceship Fuel Check
Mission control has already worked out the fuel needed for your trip. Create hasTripFuel to return true when available fuel is at least needed, or false when it is not enough. Examples hasTripFuel(30, 40) // false hasTripFuel(40, 40) // true hasTripFuel(50, 40) // true Notes available and needed are whole numbers from 0 to 1000. The exact amount is enougCan This Meeting Fit?
You have one available time block and one proposed meeting. Each is written as [start, end]. Create meetingFits to return true if the whole meeting fits inside the available block. Otherwise, return false. The meeting may start or end exactly at the block's boundary. Examples meetingFits([9,12], [10,11]) // true meetingFits([9,12], [8,10]) // false meetingOpen 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 aFeeding 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 dinoPay 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.Points 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.