Skip to content

About

Interactive rating component challenge from frontend mentor.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

Frontend Mentor - Interactive rating component solution

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.

Table of contents

Note: Delete this note and update the table of contents based on what sections you keep.

Overview

The challenge

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

Screenshot

Links

My process

Built with

  • Semantic HTML5 markup
  • CSS custom properties
  • Flexbox

What I learned

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)); // 2

I 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;
}

Useful resources

Author

About

Interactive rating component challenge from frontend mentor.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages