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:
- The button's id is btn.
- 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.
- The button has the following style properties:
- A width of 96px.
- A height of 48px.
- The font-size attribute is 24px.
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>
1 Comments
Solution is not correct. btn.innerHTML+=2 will concatenate 2 as string
ReplyDelete