Pure JavaScript Stars Generator All In One
padStart & padEnd
// const rating = stars => `★★★★★☆☆☆☆☆`.slice(5 - stars, 10 - stars);
// const rating = stars => `☆☆☆☆☆`.padStart(5 - stars, '★');
// const rating = stars => `★★★★★`.padEnd(5 - stars, '☆');
// const rating = stars => ``.padStart(stars, '★') + ``.padEnd(5 - stars, '☆');
const rating = stars => ``.padStart(stars, '★').padEnd(5, '☆');
const showStars = (color, stars) => {
var div = document.createElement("div");
div.append(`rating(${stars}) => ${rating(stars)}`)
div.style.color = color || 'green';
document.getElementById('stars').append(div);
}
showStars('MediumSpringGreen', 5)
showStars('MediumTurquoise', 4)
showStars('yellow', 3)
showStars('coral', 2)
showStars('orange', 1)
showStars('red', 0)