Menu
Coddy logo textTech

function appendToDisplay

Lesson 11 of 14 in Coddy's DOM Project - Calculator course.

We need to create four functions, which are:

  1. appendToDisplay: to display the value of the clicked number or symbol
  2. clearDisplay: to clear everything on the display (C)
  3. deleteLast: to delete each number or symbol (backspace functioning)
  4. calculateResult: After clicking on the equal button, a result is generated.
challenge icon

Challenge

Easy
  1. Create a function appendToDisplay that has a value as a parameter and appends the numbers or symbols to the 'display'.
  2. 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