Showing posts with label Youtube Likes. Show all posts
Showing posts with label Youtube Likes. Show all posts

Wednesday, November 9, 2022

Youtube Likes - JS do while loop, JS for in, JS Getters & Setters, JS This keyword, DOM Model


Youtube Likes:

We've all seen the like and dislike buttons on youtube. There is a number that shows the count of total likes. Let's replicate that feature of Youtube and use it in our own social networking site.

Acceptance Criteria:

  • Render two buttons. The Like button should have id="increment". The dislike button should have id="decrement"

  • There should be a h3 element that displays the count of the count of Likes. This element should have id="counter"

  • The count should not go below zero. If dislike button is pressed when count is 0, it should remain at 0
HTML:
<!DOCTYPE html>
<html>
    <body>
<button id="increment" onclick="inc()">Like</button>


<button id="decrement" onclick="dec()">Dislike</button>

<h3 id="counter">0</h3>
</body>
</html>


JS:

var c=0;

function inc()
{
c++;
document.getElementById("counter").innerText = c;
}

function dec(){
    if(c>0)
    {
        c--;
        document.getElementById("counter").innerText = c;
    }
}



Output:











ads vert

Basic HTML Tables - Layout, HTML Tables, Attributes, Aside, Footer, Tr tag, Td tag, Th tag, Tbody

  Basic HTML Tables - Layout, HTML Tables, Attributes, Aside, Footer, Tr tag, Td tag, Th tag, Tbody < table >      < thead >    ...