Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank, 10 Days Of JavaScript. At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.
In this post, you will find the solution for Day 9: Binary Calculator in JavaScript-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.
Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.
Introduction To JavaScript
JavaScript is a lightweight, cross-platform, and interpreted scripting language. It is well-known for the development of web pages, many non-browser environments also use it. JavaScript can be used for Client-side developments as well as Server-side developments. JavaScript contains a standard library of objects, like Array, Date, and Math, and a core set of language elements like operators, control structures, and statements.
Advantages of JavaScript
The merits of using JavaScript are −
- Less server interaction − You can validate user input before sending the page off to the server. This saves server traffic, which means less load on your server.
- Immediate feedback to the visitors − They don’t have to wait for a page reload to see if they have forgotten to enter something.
- Increased interactivity − You can create interfaces that react when the user hovers over them with a mouse or activates them via the keyboard.
- Richer interfaces − You can use JavaScript to include such items as drag-and-drop components and sliders to give a Rich Interface to your site visitors.
Link for the Problem – Day 9: Binary Calculator – Hacker Rank Solution
Day 9: Binary Calculator – Hacker Rank Solution
Problem:
Objective
In this challenge, we implement a calculator that uses binary numbers. Check out the attached tutorial for learning materials.
Task
Implement a simple calculator that performs the following operations on binary numbers: addition, subtraction, multiplication, and division. Note that division operation must be integer division only; for example, , , and .
The calculator’s initial state must look like this:
![Day 9: Binary Calculator in JavaScript | 10 Days Of JavaScript Solutions | HackerRank Programming Solutions [💯Correct] 2 image](https://s3.amazonaws.com/hr-challenge-images/0/1456642859-ad1191f53b-ScreenShot2016-02-28at12.29.21PM.png)
- Element IDs. Each element in the document must have an
id
, specified below:innerHTML
id
Description/Behaviorres
Contains the result of button presses.btns
A button container that displays all eight calculator buttons.0
btn0
A button expressing binary digit .1
btn1
A button expressing binary digit .C
btnClr
A button to clear the contents of .=
btnEql
A button to evaluate the contents of the expression in .+
btnSum
A button for the addition operation.-
btnSub
A button for the subtraction operation.*
btnMul
A button for the multiplication operation./
btnDiv
A button for the integer division operation. - Styling. The document’s elements must have the following styles:
body
has awidth
of33%
.res
has abackground-color
oflightgray
, aborder
that issolid
, aheight
of48px
, and afont-size
of20px
.btn0
andbtn1
have abackground-color
oflightgreen
and acolor
ofbrown
.btnClr
andbtnEql
have abackground-color
ofdarkgreen
and acolor
ofwhite
.btnSum
,btnSub
,btnMul
, andbtnDiv
have abackground-color
ofblack
, acolor
ofred
.- All the buttons in
btns
have awidth
of25%
, aheight
of36px
, afont-size
of18px
,margin
of0px
, andfloat
valueleft
.
The .js
and .css
files are in different directories, so use the link tag to provide the CSS file path and the script tag to provide the JS file path:
<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="css/binaryCalculator.css" type="text/css"> </head> <body> <script src="js/binaryCalculator.js" type="text/javascript"></script> </body> </html>
Constraints
- All expressions in the test dataset are entered in the form , where is the first binary number, is the second binary number, and is in the set .
- Both operands will always be positive integers when converted from base- to base-.
- All expressions will be valid.
Explanation
Consider the following sequence of button clicks:
Before pressing the button, the result div looks like this:
![Day 9: Binary Calculator in JavaScript | 10 Days Of JavaScript Solutions | HackerRank Programming Solutions [💯Correct] 3 27+8](https://s3.amazonaws.com/hr-challenge-images/18103/1456666017-1857ab934b-ScreenShot2016-02-28at6.55.52PM.png)
After pressing the button to evaluate our expression, the result div looks like this:
![Day 9: Binary Calculator in JavaScript | 10 Days Of JavaScript Solutions | HackerRank Programming Solutions [💯Correct] 4 27+8eval](https://s3.amazonaws.com/hr-challenge-images/18103/1456666141-da2d0c1331-ScreenShot2016-02-28at6.58.38PM.png)
Notice that , , and , so our calculator evaluated the expression correctly.
Now, let’s consider our next sequence of button clicks as:
Before pressing the button, the result div looks like this:
![Day 9: Binary Calculator in JavaScript | 10 Days Of JavaScript Solutions | HackerRank Programming Solutions [💯Correct] 5 141x7](https://s3.amazonaws.com/hr-challenge-images/18103/1456666566-39a02c93ac-ScreenShot2016-02-28at7.04.23PM.png)
After pressing the button to evaluate our expression, the result div looks like this:
![Day 9: Binary Calculator in JavaScript | 10 Days Of JavaScript Solutions | HackerRank Programming Solutions [💯Correct] 6 141x7eval](https://s3.amazonaws.com/hr-challenge-images/18103/1456666602-bb107fb013-ScreenShot2016-02-28at7.05.26PM.png)
Consider the next sequence of button clicks as:
The result div looks like this:
![Day 9: Binary Calculator in JavaScript | 10 Days Of JavaScript Solutions | HackerRank Programming Solutions [💯Correct] 7 clear3](https://s3.amazonaws.com/hr-challenge-images/18103/1456667223-af168e6fc7-ScreenShot2016-02-28at7.16.38PM.png)
Day 9: Binary Calculator – Hacker Rank Solution
<!-- HTML --> <input id="res"></input> <div id="btns"> <button id="btn0">0</button> <button id="btn1">1</button> <button id="btnClr">C</button> <button id="btnEql">=</button> <button id="btnSum">+</button> <button id="btnSub">-</button> <button id="btnMul">*</button> <button id="btnDiv">/</button> </div>
/* CSS */ body { width: 33%; } #res { background-color: light-gray; border: solid; height: 48px; font-size: 20px; } button { width: 25%; height: 36px; font-size: 18px; margin: 0px; float: left; } #btn0, #btn1 { background-color: lightgreen; color: brown; } #btnClr, #btnEql { background-color: darkgreen; color: white; } #btnSum, #btnSub, #btnMul, #btnDiv { background-color: black; color: red; }
// Work in progress! // JS const ids = [1, 2, 3, 6, 9, 8, 7, 4]; // start position ids in clockwise order let nums = [1, 2, 3, 6, 9, 8, 7, 4]; // rotate in clockwise order let btn5 = document.getElementById("btn5"); btn5.onclick = function() { nums.unshift(nums.pop()); for (i = 0; i <= 7; i++) { document.getElementById("btn" + ids[i]).innerHTML = nums[i]; } };
order cialis 40mg pills buy cialis 40mg pills buy ed medication
buy estradiol 2mg generic lamictal price order minipress 1mg without prescription
generic mebendazole 100mg order retin gel generic buy tadalafil online cheap
metronidazole 200mg cheap buy generic septra over the counter keflex without prescription
buy avanafil for sale tadacip order online voltaren 100mg pills
indocin ca purchase indomethacin online cheap buy generic cefixime over the counter
buy trimox medication generic anastrozole 1 mg order biaxin 500mg online
buy catapres generic order spiriva 9mcg sale order tiotropium bromide 9mcg for sale
where can i buy careprost order desyrel 100mg pills buy trazodone paypal
order minocin 50mg generic brand hytrin 5mg actos order online
buy leflunomide cheap viagra 50mg us azulfidine pill
oral accutane 20mg order azithromycin 500mg pills azithromycin price
cheap cialis without prescription tadalafil 5mg pills order cialis 40mg
azithromycin 500mg pill buy omnacortil medication gabapentin 800mg tablet
ivermectin dosage male ed pills prednisone online
buy lasix 100mg sale buy ventolin inhalator generic buy cheap generic ventolin
cost levitra 20mg hydroxychloroquine oral order plaquenil 400mg pill
order ramipril 10mg online arcoxia 120mg cheap order arcoxia 60mg generic
levitra 10mg generic tizanidine for sale hydroxychloroquine over the counter
cost benicar 20mg how to buy calan buy cheap generic divalproex
cost coreg 25mg order chloroquine generic buy chloroquine online cheap
brand diamox 250 mg order azathioprine 25mg online cheap buy imuran 25mg pills
buy lanoxin 250 mg for sale digoxin 250 mg drug order molnupiravir 200 mg generic
order naprosyn 250mg online order omnicef 300 mg for sale generic lansoprazole 15mg
order olumiant 2mg online order baricitinib 4mg for sale order lipitor 20mg online cheap
buy albuterol online cheap pantoprazole 20mg pyridium 200mg cost