Первая программа
Здравствуйте, написал первую программу под браузер на JavaScript + jQuery, т.к. ещё только начинающий, прошу сказать, что можно было бы сделать лучше (прошу не бить палками и не мочиться мне на лицо за корявость кода)
html: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <title>Page</title> <link href="Style.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery-3.1.0.min.js"></script> <script type="text/javascript" src="script.js"></script> </head> <body> <p><b>Квадратное уравнение: <i>ax<sup>2</sup>+bx+c</i></p></b><br/><br/> <b id="prim"></b></br></br> <div>a = <input id="a"></input></br></br></div> <div>b = <input id="b"></input></br></br></div> <div>c = <input id="c"></input></br></br></div> <b id="answ"></b><br/><br/> <b id="D"></b><br/> <b id="D1"></b><br/><br/> <b id="x1"></b><br/> <b id="x2"></b><br/> <b id="x"></b><br/><br/> <b id="answer"></b><br/><br/> </body> </html> css: body { background: url(jabka1.jpg); } button{ margin: 10px; padding: 10px; } b{ font-size: 20px; padding: 1px; margin-left: 10px; } input{ margin-left: 20px; } js: jQuery('document').ready(function(){ jQuery('input').on('keyup', function(){ var a, b, c, x, x1, x2; a = jQuery("#a").val(); a = parseInt(a); b = jQuery("#b").val(); b = parseInt(b); c = jQuery("#c").val(); c = parseInt(c); jQuery("#prim").html(a+"x<sup>2</sup>+"+b+"x+"+c+"=0"); var D = b*b-4*a*c; var dCor = Math.sqrt(D); jQuery("#answ").html("a = "+a+"; b = "+b+"; c = "+c+";"); jQuery("#D").html("D = "+b+"<sup>2</sup>-4 * "+a+" * "+c+" = "+D); if(D === 0){ x = -b/a*2; jQuery("#D1").html("D = 0, один корень"); jQuery("#x1").html("x = "+"-b/a*2"); jQuery("#x2").html(""); jQuery("#x").html("x = "+ x); jQuery("#answer").html("Ответ: x = "+x); }else if(D < 0){ jQuery("#D1").html("D < 0, корней нет"); jQuery("#x1").html(""); jQuery("#x2").html(""); jQuery("#answer").html("Ответ: корней нет"); }else if(D != D){ jQuery("#D1").html(""); jQuery("#x").html(""); jQuery("#x1").html(""); jQuery("#x2").html(""); jQuery("#answer").html(""); jQuery("#prim").html(""); jQuery("#answ").html(""); jQuery("#D").html(""); }else{ jQuery("#D1").html("D > 0, два корня"); x1 = (-b + dCor)/2*a; jQuery("#x1").html("x<sub>1</sub> = (-"+b+"+ √<i><span>"+D+ "</span></i>)/(2 * "+ a + ") = "+x1); x2 = (-b - dCor)/2*a; jQuery("#x2").html("x<sub>2</sub> = (-"+b+"- √<i><span>"+D+ "</span></i>)/(2 * "+ a + ") = "+ x2); jQuery("#x").html(""); jQuery("#answer").html("Ответ: x<sub>1</sub> = "+x1+ "; x<sub>2</sub> = "+x2); } }); }); |
Работает? Значит всё ок.
Посоветовать можно заключать код на форумах в соответствующие теги, здесь это [JS][/JS] и [HTML][/HTML] соответственно. |
Часовой пояс GMT +3, время: 06:49. |