← Back to challenges

One Button Messaging Device

JavaScriptHardlogicmathloops

Instructions

Imagine a messaging device with only one button. For the letter A, you press the button one time, for E, you press it five times, for G, it's pressed seven times, etc, etc.

Write a function that takes a string (the message) and returns the total number of times the button is pressed.

Examples

howManyTimes("abde") ➞ 12

howManyTimes("azy") ➞ 52

howManyTimes("qudusayo") ➞ 123

Notes

  • Ignore spaces.
  • The given string argument will be in lower case.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Return an Array of Subarrays