DEV Community

Madalina Pastiu
Madalina Pastiu

Posted on

Parse nice int from char problem

Instructions:

You ask a small girl,"How old are you?" She always says, "x years old", where x is a random number between 0 and 9.

Write a program that returns the girl's age (0-9) as an integer.

Assume the test input string is always a valid string. For example, the test input may be "1 year old" or "5 years old". The first character in the string is always a number.

Thoughts:

First I want to isolate the 1st string element,since is always a number.After this, I transform it into a number.

Solution:

function getAge(inputString){
// return the girl's correct age as an integer. Happy coding :) 
  return Number(inputString[0]);
}
Enter fullscreen mode Exit fullscreen mode

This is a CodeWars Challenge of 8kyu Rank

Top comments (0)