-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDay8.CreateAButton.html
88 lines (67 loc) · 2.43 KB
/
Day8.CreateAButton.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Objective
// In this challenge, we practice creating buttons in JavaScript. Check out the attached tutorial for learning materials.
// Task
// 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 . After each click, the button must increment by . 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.
// The .js and .css files are in different directories, so use the link tag to provide the CSS file path and the script tag to provide the JS file path:
// <!DOCTYPE html>
// <html>
// <head>
// <link rel="stylesheet" href="css/button.css" type="text/css">
// </head>
// <body>
// <script src="js/button.js" type="text/javascript"></script>
// </body>
// </html>
// Submissions
// This is a new style of challenge involving Front-End rendering. It may take up to seconds to see the result of your code, so please be patient after clicking Submit. The Submissions page contains screenshots to help you gauge how well you did.
// Ask questions in the Discussions forum and submit any bug reports to support@hackerrank.com. Enjoy!
// Explanation
// Initially, the button looks like this:
// initial
// After the first clicks, it looks like this:
// four clicks
// After more clicks, it looks like this:
// nine clicks
// Submissions: 1994
// Max Score: 20
// Difficulty: Easy
// Rate This Challenge:
// Need Help?
// Button Basics in JavaScript
// More
<!-- Enter your HTML code here -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Button</title>
<link rel="stylesheet" href="css/button.css" type="text/css">
<style>
.button {
width: 96px;
height: 48px;
font-size: 24px;
}
</style>
</head>
<body>
<script>
var clickBtn = document.createElement('button');
let counter = 0;
clickBtn.innerHTML = counter;
clickBtn.id = 'btn';
clickBtn.className = 'button';
document.body.appendChild(clickBtn);
clickBtn.onclick = function () {
counter++;
btn.innerHTML = counter.toString();
};
</script>
</body>
</html>