PHP 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 returnTrue() { } All you have to do is type return true; between the curly braces { } and then click the Check button. If you did this correctly, a celebration window will pop up. Notes Don't forget to end lines wiReturn 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.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.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.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 SolutioMaximum Edge of a Triangle
Create a function that finds the maximum range of a triangle's third edge, where the side lengths are all integers. Examples nextEdge(8, 10) ➞ 17 nextEdge(5, 7) ➞ 11 nextEdge(9, 2) ➞ 10 Notes (side1 + side2) - 1 = maximum range of third edge. The side lengths of the triangle are positive integers. Don't forget to return the result.Return Something to Me!
Write a function that returns the string "something" joined with a space " " and the given argument a. Examples giveMeSomething("is better than nothing") ➞ "something is better than nothing" giveMeSomething("Bob Jane") ➞ "something Bob Jane" giveMeSomething("something") ➞ "something something" Notes Assume an input is given.Return the First Element in an Array
Create a function that takes an array containing only numbers and return the first element. Examples getFirstValue([1, 2, 3]) ➞ 1 getFirstValue([80, 5, 100]) ➞ 80 getFirstValue([-500, 0, 50]) ➞ -500 Notes The first element in an array always has an index of 0.Convert Hours into Seconds
Write a function that converts hours into seconds. Examples howManySeconds(2) ➞ 7200 howManySeconds(10) ➞ 36000 howManySeconds(24) ➞ 86400 Notes 60 seconds in a minute, 60 minutes in an hour Don't forget to return your answer.Is the Number Less than or Equal to Zero?
Create a function that takes a number as its only argument and returns true if it's less than or equal to zero, otherwise return false. Examples lessThanOrEqualToZero(5) ➞ false lessThanOrEqualToZero(0) ➞ true lessThanOrEqualToZero(-2) ➞ true Notes Don't forget to return the result. If you get stuck on a challenge, find help in the Resources tab. If you'reThe Farm Problem
In this challenge, a farmer is asking you to tell him how many legs can be counted among all his animals. The farmer breeds three species: chickens = 2 legs cows = 4 legs pigs = 4 legs The farmer has counted his animals and he gives you a subtotal for each species. You have to implement a function that returns the total number of legs of all the animals. ExReturn the Remainder from Two Numbers
There is a single operator in PHP, capable of providing the remainder of a division operation. Two numbers are passed as parameters. The first parameter divided by the second parameter will have a remainder, possibly zero. Return that value. Examples remainder(1, 3) ➞ 1 remainder(3, 4) ➞ 3 remainder(-9, 45) ➞ -9 remainder(5, 5) ➞ 0 Notes The tests only usPlayer Two Has Joined
Someone has joined your game! Create join_message to return their username followed by " has joined!". For "Nova", return "Nova has joined!". Examples join_message("Nova") // "Nova has joined!" joinmessage("Pixel7") // "Pixel_7 has joined!" join_message("x") // "x has joined!" Notes username contains 1 to 20 English letters, digits or underscores. Keep iMake It a Hashtag
Turn one word into a hashtag. Create make_hashtag to put "#" before word and return the new string. Keep the word just as it is. Examples make_hashtag("coding") // "#coding" make_hashtag("PixelArt") // "#PixelArt" make_hashtag("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 playlist_name to return mood followed by " Mix". For "Late Night", return "Late Night Mix". Examples playlist_name("Late Night") // "Late Night Mix" playlist_name("Focus") // "Focus Mix" playlist_name("Rainy Day") // "Rainy Day Mix" Notes mood is a nonempty string of at most 30 characters, with no spaceOne More Encore
The crowd wants one more song! Create encore_total to return the total number of songs after the band adds one encore to songs. Examples encore_total(8) // 9 encore_total(0) // 1 encore_total(20) // 21 Notes songs is a whole number from 0 to 100. The encore always adds exactly one song.Retry or Stop?
Create should_retry 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 should_retry(true, 2, 3) // true should_retry(false, 2, 3) // false should_retry(true, 3, 3) // false Notes failed is a boolean. attempts is the number of attempts already made,Will the Next File Fit?
A drive has capacity megabytes of space, and used megabytes are already taken. Create file_fits to return true if a file of size megabytes will fit. Otherwise, return false. Filling the drive exactly is allowed. Examples file_fits(100, 70, 20) // true file_fits(100, 70, 31) // false file_fits(100, 70, 30) // true Notes All three numbers are whole numbersIs the String Empty?
Create a function that returns true if a string is empty and false otherwise. Examples isEmpty("") ➞ true isEmpty(" ") ➞ false isEmpty("a") ➞ false Notes A string containing only whitespaces " " does not count as empty. 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 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.