I am very new to algorithm and programming in general. I may require more explanation than an average fellow. Apologies in advance.
My aim is to Create a function that returns a number, based on the string provided. I have been told that this can be done using loops. I believe my errors lies in the if statement. However, cant seem to figure it out. I would be glad if somebody could help.
function word(s) {
let str = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "zero"];
let int = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
for (let j = 0; j < int.length; j++) {
for (let i = 0; i < str.length; i++) {
if (s === str[i]) {
return int[j]
}
}
}
}