Header Ad

HackerRank Day 8: Create a Button 10 Days of javascript solution

In this HackerRank Day 8: Create a Button 10 Days of javascript problem you need to Complete the code in the editor so that it creates a clickable button satisfying the following properties:

  1. The button's id is btn.
  2. The button's initial text label is 0. After each click, the button must increment by 1. Recall that the button's text label is the JS object's innerHTML property.
  3. The button has the following style properties:
  4. A width of 96px.
  5. A height of 48px.
  6. The font-size attribute is 24px.

HackerRank Day 8: Create a Button 10 Days of javascript solution


HackerRank Day 8: Create a Button 10 Days of javascript problem solution.

CSS file.


.btnClass {

    width: 96px;

    height: 48px;

    font-size: 24px;

}


JavaScript file

var btn = document.createElement("Button");


btn.innerHTML = "0";

btn.id = "btn";

btn.className = "btnClass";


document.body.appendChild(btn);


btn.onclick = function() {

    btn.innerHTML+=2;

}

HTML file

<!-- Enter your HTML code here -->

<!DOCTYPE html>

<html>

    <head>

        <meta charset="utf-8">

        <title>Button</title>

    </head>

    <body>

    </body>

</html>



Post a Comment

1 Comments

  1. Solution is not correct. btn.innerHTML+=2 will concatenate 2 as string

    ReplyDelete