Star rating with Javascript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Star rating with Javascript

I want to make a quiz with html, css and js. When the user clicks on a topic, another html page loads and he/she can start the quiz by clicking the start button, the problem is when the quiz finishes, I want to show the result of the quiz in the first html page(I mean the topic page) with star rating, ex: when the user correctly answers 3 questions out of 5, I want to give him/her 3 stars out of 5 in another html page (topic page). I made the stars using method in https://webdesign.tutsplus.com => "a simple Javascript technique for filling star ratings by George Martsoukos". But my attempts to color the stars according to the result of the quiz fail. Please help me out. Second, how to remember information about the user's result (I mean the number of golden stars), once the user visits the webpage in another time again? Thanks in advance :) Here is part of my code, but there is an error in javascrpt. what's wrong with style property? https://code.sololearn.com/Wx7C5GDWZDg9/?ref=app

5th Dec 2018, 9:53 AM
Aniseh Fasihi Harandi
Aniseh Fasihi Harandi - avatar
2 Answers
+ 2
Your code is working. It's just a common SL newbie issue, every newbie would encounter it. Set the JS pane, initialization as callback by onload. https://code.sololearn.com/Wq0G8dBAUMLR/?ref=app
5th Dec 2018, 10:09 AM
Calviղ
Calviղ - avatar
+ 5
//or this way window.onload = () => { var counter = 3; var star = document.getElementById("inner"); star.style.width = "60%"; };
5th Dec 2018, 10:59 AM
Алексей Р.
Алексей Р. - avatar