File tree Expand file tree Collapse file tree 3 files changed +89
-0
lines changed
69. Deciaml To Binary Converter Expand file tree Collapse file tree 3 files changed +89
-0
lines changed Original file line number Diff line number Diff line change 1+ let result = document . querySelector ( ".result-btn" ) ;
2+
3+ result . addEventListener ( "click" , decimal ) ;
4+
5+ function decimal ( ) {
6+ let decimal = document . getElementById ( "number" ) . value ;
7+ let tempDecimal ;
8+ let rem = 0 ;
9+ let binary = 0 ;
10+ let place = 1 ;
11+
12+ tempDecimal = decimal ;
13+
14+ while ( tempDecimal > 0 ) {
15+ rem = tempDecimal % 2 ;
16+ binary = binary + rem * place ;
17+ tempDecimal = parseInt ( tempDecimal / 2 ) ;
18+ place = place * 10 ;
19+ }
20+
21+ const h1 = document . createElement ( "h1" ) ;
22+ h1 . innerHTML = `${ binary } ` ;
23+
24+ // h1.style.border = "2px solid black";
25+ // h1.style.padding = "10px";
26+ // h1.style.marign = "5px";
27+
28+ const container = document . querySelector ( ".results-container" ) ;
29+ container . append ( h1 ) ;
30+ }
Original file line number Diff line number Diff line change 1+ < html lang ="en ">
2+ < head >
3+ < meta charset ="UTF-8 " />
4+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < title > Deciaml To Binary Converter</ title >
7+ < link rel ="stylesheet " href ="style.css " />
8+ </ head >
9+ < body >
10+ < section class ="container ">
11+ < input type ="number " name ="number " id ="number " />
12+ < input type ="button " value ="Check " class ="result-btn " />
13+ </ section >
14+
15+ < section class ="results-container "> </ section >
16+
17+ < script src ="app.js "> </ script >
18+ </ body >
19+ </ html >
Original file line number Diff line number Diff line change 1+ * {
2+ padding : 0 ;
3+ margin : 0 ;
4+ box-sizing : border-box;
5+ }
6+
7+ body {
8+ display : flex;
9+ justify-content : space-around;
10+ }
11+
12+ .container {
13+ width : 50% ;
14+ background : crimson;
15+ display : flex;
16+ justify-content : center;
17+ align-items : center;
18+ }
19+
20+ .container input {
21+ padding : 10px 20px ;
22+ margin-left : 10px ;
23+ outline : none;
24+ }
25+
26+ .container .result-btn {
27+ border : none;
28+ border-radius : 5px ;
29+ padding : 12px 20px ;
30+ cursor : pointer;
31+ }
32+
33+ .results-container {
34+ height : 100% ;
35+ width : 50% ;
36+ display : flex;
37+ flex-direction : column;
38+ justify-content : center;
39+ align-items : center;
40+ }
You can’t perform that action at this time.
0 commit comments