I understand most of what's been asked of me when it comes to loops, but I'm having a bit of problem understanding how to convert a for loop into a while loop
This is the code I did in a forloop
const population = [67330000, 2828000, 67750000, 47420000];
const percentages2 = [];
for (let j = 0; j < population.length; j++) {
percentages2.push((population[j] / 7900) * 100);
}
console.log(percentages2);
Basically I'm doing an assignment as part of the course I'm currently doing, but I just don't know how to do the same code in a while loop... I'm unsure if how I've done is correct, but I'll include it down below either way.. I feel as if my code here is falling into the DRY bracket...
let population = [67330000, 2828000, 67750000, 47420000];
let percentages3 = []
while (percentages3.length !== population.length) {
percentages3.push((population[0] / 7900) * 100);
percentages3.push((population[1] / 7900) * 100);
percentages3.push((population[2] / 7900) * 100);
percentages3.push((population[3] / 7900) * 100);
}
console.log(percentages3);
I appreciate anyone who can help me out 🙂