Add function to update content of screen
This commit is contained in:
parent
a378ac3cf5
commit
ea4c135b29
3 changed files with 20 additions and 2 deletions
|
|
@ -10,7 +10,7 @@
|
||||||
<header><h1>Calculator</h1></header>
|
<header><h1>Calculator</h1></header>
|
||||||
<main>
|
<main>
|
||||||
<div class="calculator">
|
<div class="calculator">
|
||||||
<div class="screen"></div>
|
<div class="screen">0</div>
|
||||||
<button class="num">1</button>
|
<button class="num">1</button>
|
||||||
<button class="num">2</button>
|
<button class="num">2</button>
|
||||||
<button class="num">3</button>
|
<button class="num">3</button>
|
||||||
|
|
@ -37,6 +37,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<script scr="script.js"></script>
|
<script src="script.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
17
script.js
17
script.js
|
|
@ -1,3 +1,20 @@
|
||||||
|
const screen = document.querySelector(".screen")
|
||||||
|
const buttons = document.querySelectorAll("button")
|
||||||
|
|
||||||
|
buttons.forEach((button) => {
|
||||||
|
button.addEventListener ("click", displayToScreen);
|
||||||
|
});
|
||||||
|
|
||||||
|
function displayToScreen() {
|
||||||
|
|
||||||
|
if(this.className == "equal") {
|
||||||
|
//testButton();
|
||||||
|
} else {
|
||||||
|
screen.textContent = this.textContent;
|
||||||
|
console.log("A button was pressed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Calculator(str) {
|
function Calculator(str) {
|
||||||
|
|
||||||
this.methods = {
|
this.methods = {
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ main {
|
||||||
grid-column: 1 / span 4;
|
grid-column: 1 / span 4;
|
||||||
height: 100px;
|
height: 100px;
|
||||||
background: #eee;
|
background: #eee;
|
||||||
|
color: #111;
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue