I'm just starting to learn JavaScript and I have to do a task:
Create function with local variables which turns each element of array [0,1,2,3,4,5] into a sqrt and sums them up.
I know how to do a function and then I have to do a loop - I have a problem with the next step and using Math.sqrt...
function myFunction() {
var numbers = ['0','1', '2', '3', '4', '5'];
var total = 1;
for (var i = 1; i < numbers.length; i++) {
var result = Math.sqrt(numbers[i++]) * +numbers[i];
console.log(result);
}
}
myFunction();