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?
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();
}
};