Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
5
Indexable
Never
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dokumen Biasa</title>
</head>
<body>
    <b id="teks">DEFAULT SET</b>
    <br>
    <button id="start" onclick="startCalculator()">START</button>
</body>
<script>
    let btnStart = document.querySelector("#start");
    let teks = document.querySelector("#teks");
    let arr = [];

    function startCalculator(){
        let a = parseInt(prompt("Masukkan angka A"));
        let opt = prompt("Masukkan operator");
        let b = parseInt(prompt("Masukkan angka B"));

        let hasil = 0;
        if(opt == "+"){
            hasil = a+b;
        }else if(opt == "-"){
            hasil = a-b;
        }else if(opt == "/"){
            hasil = a/b;
        }else if(opt == "*"){
            hasil = a*b;
        }

        arr.push(hasil);
        teks.innerText = hasil;
        console.log(arr);
    }

</script>
</html>