function appendToDisplay
Lesson 11 of 14 in Coddy's DOM Project - Calculator course.
We need to create four functions, which are:
- appendToDisplay: to display the value of the clicked number or symbol
- clearDisplay: to clear everything on the display (C)
- deleteLast: to delete each number or symbol (backspace functioning)
- calculateResult: After clicking on the equal button, a result is generated.
Challenge
Easy- Create a function appendToDisplay that has a value as a parameter and appends the numbers or symbols to the 'display'.
- Now that our function is ready, we have to make it work. So use the onclick attribute and set appendToDisplay(value) to all the buttons except ‘C’, '←', and ‘='. Below is an example:
<button class="btn" onclick="appendToDisplay('/')">/</button>(Refresh the website on the top right and click on numbers to see if it works!)
Try it yourself
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<!-- Write HTML code here -->
<script src="script.js"></script>
</body>
</html>All lessons in DOM Project - Calculator
1Introduction
What will you build?4Make it work
function appendToDisplay