0

How to add a like button and if we click on it like should also increase in javascript?

used for loop and and if statement somebody help me out can someone give me the code of this?

9th Feb 2017, 5:00 AM
akash yadav
akash yadav - avatar
1 Answer
+ 2
//Here is how you would use it, this is just an idea ofc. You can improve on it. var likes = 0; var liked = false; button = document.getElementById("LikeButton"); function show() { button.innerHTML = likes + " Likes"; } button.onclick = function() { if (liked === false) { liked = true; likes++; show(); } else { liked = false; likes--; show(); } };
9th Feb 2017, 5:07 AM
Dawzy
Dawzy - avatar