09.Loading Bar problem
Здравейте,
Някой може ли да предложи по-адекватно решение на тази задача. Аз я направих с безумно много проверки, ако някой ми покаже по-опростен вариант ще съм безкрайно благодарна!
https://pastebin.com/DG3mRtXk
Условие на задачата:
Loading Bar
You will receive a single number between 0 and 100 which is divided with 10 without residue (0, 10, 20, 30...).
Your task is to create a function that visualize a loading bar depending on that number you have received in the input.
Examples
Input |
Output |
30 |
30% [%%%.......] Still loading... |
50 |
50% [%%%%%.....] Still loading... |
100 |
100% Complete! [%%%%%%%%%%] |
Супер! Благодаря!
Супер!Благодаря!
function loadingBar(number){
let loadingbar = [".",".",".",".",".",".",".",".",".","."]
let splicedPosition = 0
for (let i = 10; i <= number; i+= 10) {
if (number % i >= 0){
loadingbar.splice(splicedPosition,1,'%')
splicedPosition++
if (splicedPosition === 10){
console.log(`${number}% Complete!`)
console.log(`${number}% [${loadingbar.join("")}]`)
return;
}
}
}
console.log(`${number}% [${loadingbar.join("")}]`)
console.log('Still loading...')
}