Hi, @thaiscode. How are you?
First, I would like to save the input value on click, but I couldn't, so I did it with the num attribute in the function.
You can get the input value using the "value" property of the input. When you click on the radio button. In the JS using the click
eventListener, you can get the value using e.target.value
and save it in a variable.
Also, I would like to display an alert for when the submit button is clicked without choosing a number. Initially the variable btn has the value undefined. I tried as follows: function onSubmit() { if (btn == undefined){ alert('') } else { state1.style.display = 'none' state2.style.display = 'flex' } }
You can create a global variable in the JS to store the rating value. When the submit button is clicked, check if the rating variable has the rating value. If it doesn't have, it means no rating was selected.
btn==undefined
because you're declaring btn in a different function. btn
is a local scope variable inside the onRating
function and not a global scope. If you'll declare it outside of onRating
function and use inside onRating
and onSubmit
function. It will work.
- You should not write JS inside the HTML. It creates readability issues. You should keep the JS inside JS file.
I have written this little demo to show, how you can write the rating part of the code. Read and modify it and learn from it. If you don't understand something, feel free to reach me. https://codepen.io/pradeeps4ini/pen/OJvZGev
-
You don't have to use min-width: 375px
on the body. It adjust itself according to the content in it. You're using max-width: 90vh
on the <main>, which makes its size too wide at few points when i resize the window. You should use a fixed value here. For example: max-width: 550px
.
-
You can create utilities classes for properties, you're using on multiple elements. For example:
.flex {
display: flex;
}
and use class="flex"
, on elements where you want to use flexbox.
You have done a good job implementing the design. Have fun and keep learning.:)