Skip to content

Instantly share code, notes, and snippets.

@RichardsonColin
Created April 20, 2024 23:17
Show Gist options
  • Save RichardsonColin/685cb7df7c70e986c1d5fdb00c6c5d53 to your computer and use it in GitHub Desktop.
Save RichardsonColin/685cb7df7c70e986c1d5fdb00c6c5d53 to your computer and use it in GitHub Desktop.
=begin
Directions
- Write a method that accepts a 10 character string of letters (both uppercase and lowercase)
- if 10 characters in length:
- define an empty string to a variable (phone_num) - *already done
- loop through 10 character string (word) - *already done
- compare letter to telephone mappings and concatenate to the variable (phone_num)
- return the variable (phone_number)
- else:
- return false
----------------
- You may need to ensure the letter casing of the input string
=end
def yellow_pager(word)
# concat number characters onto this variable (phone number)
phone_num = ""
# ** complete the if expression and statement to meet the condition **
if word.length
word.each_char do |letter|
# ** complete the conditions to map letters to numbers **
phone_num += letter
end
# ** return the mapped phone number **
else
# ** return false **
end
end
# ** call method using the given variable as the argument (you may need to print (puts) the return value) **
word = "Lighthouse"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment