Design comparison
Solution retrospective
Hello community!!! This is my first project with JavaScript. I have been using the forEach loop and onclick but I had a bit of trouble:
- I can't set a single vote selection, so the user can select more than one vote.
- I had to delete the form because the otherwise the submit would not work.
I need your advice to improve the code and to learn! Thanks to everyone!
Community feedback
- @correlucasPosted about 2 years ago
πΎHello @fedementre, Congratulations on completing this challenge!
Your component is perfect, but is not responsive yet, this is due the
fixed width
you've applied to the container.Look both
width
andmax-width
the main difference between these properties is that the first(width) is fixed and the second(max-width) isflexible
, for example, a component withwidth: 320px
will not grow or shrink because the size will be ever the same, but a container withmax-width: 320px
ormin-width: 320px
can grow or contract depending of the property you've set for the container. So if you want a responsive block element, never usewidth
choose ormin-width
ormax-width
.βοΈ I hope this helps you and happy coding!
Marked as helpful0@fedementrePosted about 2 years ago@correlucas That's right, I had forgotten this important rule! Thank you so much!
0 - @VCaramesPosted about 2 years ago
Hey there! π Here are some suggestions to help improve your code:
Regarding you questions,
- Do what Adriano said in the previous comment.
- When using any type of Inputs they need to be wrapped in a Form Element. The reason why your code was not working with the Form Element is because you used Buttons to create the ratings.
The βrating buttonsβ should be built using an Input Radio and it should have a Label Element attached to it.
If you have any questions or need further clarification, let me know.
Happy Coding! π»π
Marked as helpful0@fedementrePosted about 2 years ago@vcarames Thank you very much! This comment was very important as I learned how to use radio inputs! Now, however, I have another problem. If I go to insert the SUBMIT button inside the form, it does not work correctly, surely the problem is due to the action attribute inside the form element. I am trying to solve it. Anyway, thank you very much! You have been very kind!
0@fedementrePosted about 2 years ago@vcarames I just find solution! To make the form not reload the page I inserted this action
<form action="javascript:void(0)">
0 - @AdrianoEscarabotePosted about 2 years ago
Hello @fedementre, how are you?
to solve your problem, we can use this attribute on css:
.star-container::focus { background-color: #FB7413; }
to make the submit button available only when the user selects a number, we can do this:
ratings.forEach(ratings => { ratings.onclick = event=>{ const ratingValue=ratings.textContent const paragraph = document.querySelector(".utent-rating") paragraph.innerHTML= `You selected ${ratingValue} out of 5` submit.onclick = event=>{ box1.style.display="none" box2.style.display="inline" } } });
the rest is great!!
Marked as helpful0@VCaramesPosted about 2 years agoHey @AdrianoEscarabote!
I'm currently working on this challenge. The "make the submit button available only when the user selects a number" is one of the features that I want to implement.
If you do not mind...How would I implement this? Do I give the button a class and remove it with JS?
0@AdrianoEscarabotePosted about 2 years ago@vcarames yea! you can put the
disabled
attribute directly in the HTML, and then when the user selects some number, you can even use the same code block to remove thedisabled
attribute with theremoveAttribute("disabled")
method0@VCaramesPosted about 2 years ago@AdrianoEscarabote
Awesome! Thank you!! This definitely helps!
1@fedementrePosted about 2 years ago@AdrianoEscarabote thank you so much! You are great!
0@AdrianoEscarabotePosted about 2 years ago@fedementre no problem, keep coding!!
Marked as helpful0
Please log in to post a comment
Log in with GitHubJoin 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