I am trying to solve a challenge from jshero.net. The challenge is:
Write a function parseFirstInt that takes a string and returns the first integer present in the string. If the string does not contain an integer, you should get NaN. parseFirstInt('No. 10') should return 10 and parseFirstInt('Babylon') should return NaN. The solution I came up with is:
function parseFirstInt(num){
let input=parseInt();
if(Number.isNaN(num)){
return NaN} else {
return num[0]}
}
But it doesn't work. It returns the following errors:
parseFirstInt('No. 10') does not return 10, but 'N'.
Test-Error! Correct the error and re-run the tests!
Do you guys have any ideea how to solve it?