I am trying to create a simple JavaScript program that allows users to like and dislike content. However, I am new to JavaScript and finding it a bit challenging. Basically, when the user clicks on the Follow button, the "countF" variable should increase by 1 and the button text should change to "Unfollow". It's a basic program but I'm struggling with making it work in reverse. In other words, when the Unfollow button is clicked, the "countF" should decrease by 1 and the button text should revert back to "Follow". I know it sounds simple, but I just can't seem to figure it out. Any help or ideas on how to complete this task?
var countF = 0;
var btnText = "Unfollow";
var countButton = document.getElementById("followButton");
var displayCount = document.getElementById("followers");
countButton.onclick = function() {
countF++;
followers.innerHTML = countF;
var countButton = document.getElementById("followButton");
countButton.innerHTML = btnText;
if(countButton.innerHTML = btnText) {
countF--;
countButton.innerHTML = "Follow";
}
}
<div id="followers">0</div>
<button id="followButton"></button>