By GokiSoft.com| 11:06 13/06/2020|
Học JS

[Share Code] Phương trình bậc nhất ax+b=0 javascript - giải phương trình bậc nhất ax+b=0 - a*x+b=0 javascript - Prompt trong Javascript

Yêu cầu xây dựng trang web như sau

Khi người dùng click vào "Nhập Giá Trị A", "Nhập Giá Trị B" => Xuất hiện prompt để nhập dữ liệu tương ứng

Khi người dùng click vào In Kết Quả -> Hiển thị alert về kết quả tính toán được.

Lời giải

#events-in-javascript.html


<!DOCTYPE html>
<html>
<head>
	<title>Events in Javascript</title>

	<style type="text/css">
		.panel {
			display: block;
		}

		.panel .panel-heading {
			background-color: #4287f5;
			height: 30px !important;
			color: white;
			font-size: 20px;
			padding: 10px;
		}

		.panel .panel-body {
			background-color: grey;
			height: 30px;
			padding: 20px;
		}

		.button {
			background-color: #f27f55;
			color: white;
			font-size: 18px;
		}
	</style>
</head>
<body>
	<div class="panel">
		<div class="panel-heading">
			Giai phuong trinh bac nhat ax+b=0
		</div>	
		<div class="panel-body">
			<button class="button" onclick="nhapA()">Nhap A</button>
			<button class="button" onclick="nhapB()">Nhap B</button>
			<button class="button" onclick="printResult()">In Ket Qua</button>
		</div>
	</div>

	<script type="text/javascript">
		var a, b;

		function nhapA() {
			a = prompt('Nhap A')
		}

		function nhapB() {
			b = prompt('Nhap B')
		}

		function printResult() {
			if(a == 0) {
				if(b == 0) {
					alert('PTVSN')
				} else {
					alert('PTVN')
				}
			} else {
				x = -b/a
				alert(x)
			}
		}
	</script>
</body>
</html>


Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)