Phương trình bậc nhất js
RUN
<!DOCTYPE html> <html> <head> <title>Javascript freetuts</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <form> Nhập số a: <input type="text" id="a" value=""/> <br/> Nhập số b: <input type="text" id="b" value=""/> <br/> <span id="result"></span> <br/> <input type="button" id="giaiBtn" value="Tìm nghiệm"/> </form> <script> var button = document.getElementById('giaiBtn'); giaiBtn.onclick = function () { let a = document.getElementById('a').value; let b = document.getElementById('b').value; if (a == "" || b == "") { alert("Vui lòng nhập dữ liệu"); } else { a = Number(a); b = Number(b); giai_pt_bac_nhat(a, b); } }; function giai_pt_bac_nhat(a, b) { if (a == 0 && b == 0) { alert('Phương trình vô số nghiệm'); } else if (a != 0 && b == 0) { alert('Phương trình có nghiệm x = 0'); } else if (a == 0 && b != 0) { alert("Phương trình vô nghiệm"); } else { alert('Phương trình có nghiệm x = ' + (-b / a)); } } </script> </body> </html>
PHÓNG TO