Javascript don't work | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Javascript don't work

help me. my code js may wrong any where. Code Js var uutien=0; //ghi nho so hang var arrayindex=0; var arrayphantu= new Array(); //mang ghi nho phep tinh var arraycal_index=0; var arraycal= new Array(); //ghi nho dau var dau=false; var button_new=""; //event function clickBut(obj){ var ketqua=document.getElementById("ketqua"); var str_ketqua_old=ketqua.value; if(str_ketqua_old==0){ str_ketqua_old=""; } var type = obj.innerHTML; //alert(type); if ( type=="0" || type =="1" || type=="2" || type=="3" || type=="4" || type=="5" || type=="6" || type=="7" || type=="8" || type=="9" || type=="+/-" || type==".") { if (type=="+/-"){ if(dau){ dau=false; button_new=button_new.substring(1); }else{dau=true; button_new="-" + button_new;} }else{ button_new+=type; } ketqua.value=str_ketqua_old+ button_new; } }

6th Oct 2019, 5:01 AM
tranvansu
tranvansu - avatar
4 Answers
0
Why didn't you post this in a code? I can't fully understand your code without an explanation what it should do and what its doing wrong. Also I'd like to see the HTML for more information....
6th Oct 2019, 6:30 AM
Aaron Eberhardt
Aaron Eberhardt - avatar
0
HTML file <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>May tinh co ban</title> <link rel="stylesheet" type="text/css" href="cal.css" /> </head> <body> <div id="border-cal"> <input type="text" id="ketqua" value="0"/> <div class="clear-all"></div> <div class="button first" onClick="clickBut(this)"> CE</div> <div class="button" onClick="clickBut"> &lt;-</div> <div class="button" onClick="clickBut(this)"> %</div> <div class="button" onClick="clickBut(this)"> +</div> <div class="clear-all"></div> <div class="button first" onClick="clickBut(this)"> 7</div> <div class="button" onClick="clickBut(this)"> 8</div> <div class="button" onclick="clickBut(this)"> 9</div> <div class="button" onClick="clickBut(this)">-</div> <div class="clear-all"></div> <div class="button first" onClick="clickBut(this)"> 4</div> <div class="button" onClick="clickBut(this)"> 5</div> <div class="button" onClick="clickBut(this)" > 6</div> <div class="button" onClick="clickBut(this)">X</div> <div class="clear-all"></div> <div class="button first" onClick="clickBut(this)"> 1</div> <div class="button" onClick="clickBut(this)"> 2</div> <div class="button" onClick="clickBut(this)"> 3</div> <div class="button" onClick="clickBut(this)">/</div> <div class="clear-all"></div> <div class="button first" onClick="clickBut(this)"> 0</div> <div class="button" onClick="clickBut(this)"> +/-</div> <div class="button" onClick="clickBut(this)" >.</div> <div class="button" onClick="clickBut(this)">=</div> </div> <script type="text/javascript" src="cal.js"> </script> </body> </html>
6th Oct 2019, 8:35 AM
tranvansu
tranvansu - avatar
0
CSS file body{ font-family: 'Courier New', Courier, monospace; font-size: 20px; color: darkblue; padding: 200px 0px 0px 200px; } #border-cal{ margin: 0px; padding: 20px; border: 4px solid red; width: 325px; height: 350px; } #ketqua{ margin: 0px 0px 15px 0px; padding: 10px; text-align: right; width: 290px; border: 2px solid #af1e23; } .clear-all{ clear: both; } .button{ margin:0px 0px 20px 20px; padding: 10px 10px 10px 10px; float: left; text-align: center; text-transform: uppercase; background-color: darkgrey; color:2px solid white; width: 40px; } .button-first{ margin-left: 0px; } .button:hover{ background-color: palegreen; }
6th Oct 2019, 8:36 AM
tranvansu
tranvansu - avatar
0
Ok now I have your code (which you could have posted yourself). But what's the problem? There's no bug as far I've seen. It's just not finished yet. https://code.sololearn.com/WL2lKeau29zO/?ref=app
6th Oct 2019, 9:58 AM
Aaron Eberhardt
Aaron Eberhardt - avatar