Hi Peeps,
Was wondering about the PDF solution for " Practice exercise - Functions & Arrays"
Im having some problems to print it out in the console.
Could someone please help me complete the answer by giving me a whole example with a an answer.
Thanks for your help
Solutions from PDF
Solution:
a)
function digits (num) {
return num.toString().length;
}
// Without the .length method:
function digits1 (num) {
let counter = 0 ;
for (digit in num.toString()) {
counter++;
}
return counter;
}
b)
function sumInWord (letter, word) {
let counter = 0 ;
for (value in word) {
if (word[value] === letter) {
counter++;
}
}
return counter;
}
c)
function longerThanNumber (string, number) {
let answer = (string.length > number);
return answer;
}