This is a solution to the Interactive rating component challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
Note: Delete this note and update the table of contents based on what sections you keep.
Users should be able to:
- View the optimal layout for the app depending on their device's screen size
- See hover states for all interactive elements on the page
- Select and submit a number rating
- See the "Thank you" card state after submitting a rating
- Solution URL: GitHub
- Live Site URL: GitHub pages
- Semantic HTML5 markup
- CSS custom properties
- Flexbox
I learned more about styling ol and li. To change the counter to remove the dot after the counter that is by default applied.
I used counter-reset: item;, list-style-type: none;, content: counter(item); and counter-increment: item; for this.
ol {
counter-reset: item;
list-style-type: none;
padding: 0;
display: flex;
gap: var(--spacing-300);
margin-bottom: var(--spacing-400);
}
li {
display: inline;
padding: var(--spacing-200) var(--spacing-300);
font-size: var(--font-size-3);
font-weight: bold;
line-height: var(--spacing-300);
letter-spacing: 0.0125rem;
}
li:before {
content: counter(item);
counter-increment: item;
}I also learned how to loop over li's and find the current count in vanilla JavaScript. On StackOverflow I found someone who said that I may need to loop over the LI elements. I thought there must be a better solution to this problem. I asked AI for an answer for a similar problem. As a response I got the code:
function getLiIndex(originalLi) {
let idx = 1;
let current = originalLi;
// Move back one sibling at a time…
while (current.previousElementSibling) {
current = current.previousElementSibling;
idx++;
}
return idx;
}
const secondLi = document.querySelector('ol li:nth-child(2)');
console.log(getLiIndex(secondLi)); // 2I modified the getLiIndex to:
/**
* Counts the li elements from element passed to lowest and returns the result.
*
* @param {HTMLLIElement} li The li value you want to count from
* @returns {number}
*/
const countLiHighToLow = (li) => {
let count = 1;
while ((li = li.previousElementSibling)) {
count++;
}
return count;
}- Developer Mozilla :nth-child() - You can learn more about the css
nth-childhere. I used this to loop overol lielements. - Developer Mozilla counter-reset - You can start learning about css counters here.
- Website - Niels Bruinsma
- Frontend Mentor - @bruins001


