Ruby Challenges
How Edabit Works
This is an introduction to how challenges on Edabit work. In the Code tab you'll see a starter function that looks like this: def hello() end All you have to do is type return "hello edabit.com" on the second line and then click the Check button. If you did this correctly, the button will turn red and say SUBMIT FINAL. Click it and see what happens. NotesReturn 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.Return 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.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 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.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 lessthanorequalto_zero(5) ➞ false lessthanorequalto_zero(0) ➞ true lessthanorequalto_zero(-2) ➞ true Notes Don't forget to return the result. If you get stuck on a challenge, find help in the Resources tab. If youConvert Age to Days
Create a function that takes the age in years and returns the age in days. Examples calc_age(65) ➞ 23725 calc_age(0) ➞ 0 calc_age(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.Correct the Mistakes
Fix the code in the code tab to pass this challenge. Look at the examples below to get an idea of what the function should do. Examples squared(5) ➞ 25 squared(9) ➞ 81 squared(100) ➞ 10000 Notes READ EVERY WORD CAREFULLY, CHARACTER BY CHARACTER! Don't overthink this challenge; it's not supposed to be hard.Area of a Triangle
Write a function that takes the base and height of a triangle and return its area. Examples tri_area(3, 2) ➞ 3 tri_area(7, 4) ➞ 14 tri_area(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 SoluPower Calculator
Create a function that takes voltage and current and returns the calculated power. Examples circuit_power(230, 10) ➞ 2300 circuit_power(110, 3) ➞ 330 circuit_power(480, 20) ➞ 9600 Notes power is voltage multiplied by current.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.Maximum 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 next_edge(8, 10) ➞ 17 next_edge(5, 7) ➞ 11 next_edge(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.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.Return the Last Element in an Array
Create a function that accepts an array and returns the last item in the array. The array can be either homogeneous or heterogeneous. Examples getlastitem([1, 2, 3]) ➞ 3 getlastitem(["cat", "dog", "duck"]) ➞ "duck" getlastitem([true, false, true]) ➞ true getlastitem([7, "String", false]) ➞ false Notes Don't forget to return the result. If you get stuck oFootball Points
Create a function that takes the number of wins, draws and losses and calculates the number of points a football team has obtained so far. wins get 3 points draws get 1 point losses get 0 points Examples football_points(3, 4, 2) ➞ 13 football_points(5, 0, 2) ➞ 15 football_points(0, 0, 1) ➞ 0 Notes Inputs will be numbers greater than or equal to 0.Using the "&&" Operator
Ruby has a logical operator &&, which can also be written as and. The && operator takes two boolean values, and returns true if both values are true. Consider a && b: a is checked if it is true or false. If a is false, false is returned. b is checked if it is true or false. If b is false, false is returned. Otherwise, true is returned (as both a and b are tConcatenate First and Last Name into One String
Given two strings, firstname and lastname, return a single string in the format "last, first". Examples concat_name("First", "Last") ➞ "Last, First" concat_name("John", "Doe") ➞ "Doe, John" concat_name("Mary", "Jane") ➞ "Jane, Mary" 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 stTo the Power of _____
Create a function that takes a base number and an exponent number and returns the calculation. Examples calculate_exponent(5, 5) ➞ 3125 calculate_exponent(10, 10) ➞ 10000000000 calculate_exponent(3, 3) ➞ 27 Notes All test inputs will be positive integers. Don't forget to return the result. If you get stuck on a challenge, find help in the Resources tab. IfAre the Numbers Equal?
Create a function that returns true when num1 is equal to num2; otherwise return false. Examples issamenum(4, 8) ➞ false issamenum(2, 2) ➞ true issamenum(2, "2") ➞ false Notes Don't forget to return the result.Basketball Points
Given the number of two-point and three-point baskets a team scored, return its total points. The arguments are ordered as two-pointers first, then three-pointers. Examples points(1, 1) ➞ 5 points(7, 5) ➞ 29 points(38, 8) ➞ 100 Notes If you get stuck on a challenge, find help in the Resources tab. If you're really stuck, unlock solutions in the Solutions t