Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

HackerRank Day 9: Binary Calculator 10 Days of javascript solution

YASH PAL, 31 July 2024

In this HackerRank Day 9: Binary Calculator 10 Days of javascript problem Implement a simple calculator that performs the following operations on binary numbers: addition, subtraction, multiplication, and division.

HackerRank Day 9: Binary Calculator 10 Days of javascript solution

HackerRank Day 9: Binary calculator 10 days of javascript problem solution.

JavaScript File

var opr = “”;

var screen = document.getElementById(“res”);

screen.innerHTML = “”;

function buttonClicked(e) {

    console.log(e)

    var btn = e.target || e.srcElement;

    

    if (btn.id != “btnClr” && btn.id != “btnEql”) {

        screen.innerHTML += btn.innerHTML;

        

        if (btn.id != “btn0” && btn.id != “btn1”) {

            opr = btn.innerHTML;

        }

    } else if (btn.id == “btnEql”) {

        var str = screen.innerHTML.split(opr);

        var op1 = str[0];

        var op2 = str[1];

        

        /* The double bitwise NOT (‘~~’) is a shortcut for Math.floor() */

        screen.innerHTML = (~~eval(parseInt(op1, 2) + opr + parseInt(op2, 2))).toString(2);

        

        opr = “”;

    } else if (btn.id == “btnClr”) {

        screen.innerHTML = “”;

        opr = “”;

    }

}

CSS File

#res {

    width: 81%;

    height: 48px;

    font-size: 20px;

    background: #d3d3d3;

    border: solid;

}

.btnContainer {

    width: 90%;

}

.btnContainer > .btnStyle1, .btnStyle2, .btnStyle3 {

    width: 22%;

    height: 36px;

    font-size: 18px;

}

.btnContainer > .btnStyle1 {

    background: lightgreen;

    color: brown;

}

.btnContainer > .btnStyle2 {

    background: darkgreen;

    color: white;

}

.btnContainer > .btnStyle3 {

    background: black;

    color: red;

}

10 day of javascript coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes