0

How to insert a reward point system?

I want to add reward point system by using html.. so how can I do that?

5th Dec 2016, 3:01 PM
varun raj
varun raj - avatar
1 Odpowiedź
0
This sort of reward point system is a bit more possible using DOM within Javascript. It allows you to manipulate various html elements. You can insert js into your html with the <script> tag. To make this work, you'll want something that looks like this: <div id='score'> <!--Create div to later reference in js--> <p id='store'>Score: 0</p> <!--Your current score--> <p id='place'></p> </div> <button onclick='addScore();'>Click to add to score</button> <script> //Begin javascript var totalScore = 0; //Your current score var parent = document.getElementById("score"); //Gets the div the score will be kept in var newChild; var child; function addScore() { totalScore += 1; //Add to total score var para = document.createElement("p"); //Create new paragraph var node = document.createTextNode("Score: " + totalScore); //Create text for p para.appendChild(node); //Attach text to p if (document.getElementById('store')) { parent.removeChild(document.getElementById('store')); //Remove current score count } if (newChild) { parent.removeChild(newChild); //Remove last score } newChild = parent.insertBefore(para,document.getElementById('place')); //Get new score } </script> I have the fully functional script available on the code playground under the name "Point Add Test" if you want to save it and mess with it.
5th Dec 2016, 5:26 PM
Lux
Lux - avatar