Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

interactive rating component

@charlesmambo

Desktop design screenshot for the Interactive rating component coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


hi guys need your help on this one, I dont know if I did this one right please check my JS code, tell me if I write my JS code the right way or if there is short way to write JS cause I feel like there is something missing but I cant figure it out. Thank you

Community feedback

Mirosław 240

@miroslaw-mroczkowski

Posted

Hi Charles,

Your design looks great :)

Few tips about JS:

Instead of using addEventListener for each button, you could create:

  1. static NodeList with querySelectorAll on your num-btn class,
  2. variable (e.g. let scoreValue) to keep clicked value (but you have to set a value on each of your button)
  3. use forEach method to iterate through your NodeList
const btns = document.querySelectorAll('.num-btn)

let scoreValue = '';

const score = () => {
	btns.forEach(score => {
		score.addEventListener('click', e => {
			scoreValue = e.target.value
		})
	})
}

Then you can use your scoreValue to put it in your sub-container, but you won't need to put the index of your numArr array.

thankEl.textContent = 'You selected ${scoreValue} out of ${btns.length}'

You could also add an error message in case of not choosing any score. To do this you need to create e.g. if...else statement.

In case of any questions feel free to ask :)

Marked as helpful

0

@charlesmambo

Posted

@miroslaw-mroczkowski thanks a lot

0
Hyron 5,870

@hyrongennike

Posted

Hi @charlesmambo,

Congrats on completing the challenge

I would suggest just disabling the button until a rating is selected this can be done by adding the disabled attribute on the button and removing it when the rating is clicked currently it's empty when you click submit without selecting a rating.

Replace you body rule with the one below to center the card.

body {
    margin: 0;
    padding: 30px;
    font-family: 'Overpass', sans-serif;
    background-color: hsl(216, 12%, 8%);
    color: #fff;
    justify-content: center;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

Hope this is helpful, let me know if you have any other question.

Marked as helpful

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord