Koppelingen in nieuw tabblad openen
    • Werkrapport
    • E-mail
    • Herschrijven
    • Spraak
    • Titelgenerator
    • Slim antwoord
    • Gedicht
    • Opstel
    • Grap
    • Instagram-post
    • X-post
    • Facebook-post
    • Verhaal
    • Begeleidende brief
    • Hervatten
    • Taakbeschrijving
    • Aanbevelingsbrief
    • Ontslagbrief
    • Uitnodigingsbrief
    • Begroetingsbericht
    • Meer sjablonen proberen
  1. Creating a calculator with JavaScript, HTML, and CSS is a great beginner-friendly project to practice DOM manipulation, event handling, and arithmetic operations. Below is a complete example of a functional calculator that supports addition, subtraction, multiplication, and division.

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript Calculator</title>
    <style>
    body {font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #f2f2f2; margin: 0;}
    .calculator {width: 300px; background-color: #fff; border-radius: 15px; box-shadow: 0 8px 16px rgba(0,0,0,0.1); padding: 20px;}
    .display {width: 100%; height: 50px; text-align: right; font-size: 1.5rem; padding: 10px; margin-bottom: 20px; border: none; background-color: #ffeb3b; border-radius: 8px;}
    .buttons {display: grid; grid-template-columns: repeat(4,1fr); gap: 10px;}
    .button {background-color:#03a9f4;border:none;font-size:1.5rem;padding:20px;cursor:pointer;border-radius:10px;color:white;}
    .button:hover {background-color:#0288d1;}
    .clear {background-color:#ff5722;}
    .equal {background-color:#8bc34a;}
    .operator {background-color:#ff9800;}
    </style>
    </head>
    <body>

    <div class="calculator">
    <input type="text" id="display" class="display" disabled>
    <div class="buttons">
    <button class="button clear" onclick="clearDisplay()">C</button>
    <button class="button operator" onclick="appendOperation('/')">/</button>
    <button class="button operator" onclick="appendOperation('*')">*</button>
    <button class="button operator" onclick="appendOperation('-')">-</button>

    <button class="button" onclick="appendNumber('7')">7</button>
    <button class="button" onclick="appendNumber('8')">8</button>
    <button class="button" onclick="appendNumber('9')">9</button>
    <button class="button operator" onclick="appendOperation('+')">+</button>

    <button class="button" onclick="appendNumber('4')">4</button>
    <button class="button" onclick="appendNumber('5')">5</button>
    <button class="button" onclick="appendNumber('6')">6</button>
    <button class="button equal" onclick="calculate()">=</button>

    <button class="button" onclick="appendNumber('1')">1</button>
    <button class="button" onclick="appendNumber('2')">2</button>
    <button class="button" onclick="appendNumber('3')">3</button>
    <button class="button" onclick="appendNumber('0')">0</button>
    </div>
    </div>

    <script>
    let currentInput = '';
    let currentOperation = '';
    let previousInput = '';

    function appendNumber(number) {
    currentInput += number;
    document.getElementById('display').value = `${previousInput}${currentOperation}${currentInput}`;
    }

    function appendOperation(operation) {
    if (currentInput === '') return;
    if (previousInput !== '') calculate();
    currentOperation = operation;
    previousInput = currentInput;
    currentInput = '';
    document.getElementById('display').value = `${previousInput}${currentOperation}`;
    }

    function calculate() {
    if (previousInput === '' || currentInput === '') return;
    let prev = parseFloat(previousInput);
    let current = parseFloat(currentInput);
    let result;

    switch (currentOperation) {
    case '+': result = prev + current; break;
    case '-': result = prev - current; break;
    case '*': result = prev * current; break;
    case '/':
    if (current === 0) { alert("Cannot divide by zero"); return; }
    result = prev / current;
    break;
    default: return;
    }

    currentInput = result.toString();
    currentOperation = '';
    previousInput = '';
    document.getElementById('display').value = currentInput;
    }

    function clearDisplay() {
    currentInput = '';
    previousInput = '';
    currentOperation = '';
    document.getElementById('display').value = '';
    }
    </script>

    </body>
    </html>
    Gekopieerd.
    Feedback
  2. BUILDING A SIMPLE WEB-BASED CALCULATOR: Step-by ...

    8 nov. 2024 · In this overview, we’ll walk through every part of the code needed to create a fully functional calculator. This guide will not only provide the code but will …

  3. How to build a simple HTML CSS JavaScript calculator

    8 mei 2025 · In this step-by-step tutorial, we’ll guide you through building a fully functional calculator, from designing its interface to making it interactive. You’ll …

  4. Build a Calculator using HTML, CSS, and JavaScript ...

    12 aug. 2025 · In this tutorial, we will create a simple, functional calculator using HTML, CSS, and JavaScript. This calculator will support basic operations like …

  5. Build A Simple Calculator With HTML, CSS & JavaScript

    15 apr. 2025 · Learn how to build a simple calculator app with HTML, CSS, and JavaScript. Perfect for beginners to master the basics of web development.

  6. GitHub - davidsontiffany/javascript-calculator: A JavaScript ...

    JavaScript Calculator A simple calculator built using HTML, CSS, and JavaScript that performs basic arithmetic operations with a clean and responsive user interface.

  7. JavaScript Calculator: HTML, Functions, and Advanced …

    6 feb. 2024 · Below, we’ll explore how to make a calculator in JavaScript, taking a detailed look at the components involved, the HTML code needed, and the …

  8. Building a Simple Calculator with HTML, CSS, and …

    30 jun. 2024 · This project involves HTML for the structure, CSS for styling, and JavaScript for functionality. In this article, I’ll walk you through the process of …

  9. JavaScript Simple Calculator Program (4 Ways With Code)

    31 okt. 2025 · A JavaScript calculator is a web-based application that allows users to perform arithmetic operations directly within a web browser. It uses HTML for the structure, CSS for styling, and …

  10. How To Create a Calculator Using HTML CSS

    4 dec. 2023 · In this article, we'll walk you through a step-by-Step guide to building a fully functional calculator application from scratch using HTML, CSS and of course …

  11. Mensen vragen ook naar
    Laden
    Kan antwoord niet laden
Door deze website te gebruiken, gaat u akkoord met ons gebruik van cookies voor analysedoeleinden, inhoud die is aangepast aan uw persoonlijke voorkeur en advertenties.Meer informatie over cookies van derden|Privacybeleid van Microsoft