Skip to content

Instantly share code, notes, and snippets.

@abcprintf
Created July 19, 2019 02:34
Show Gist options
  • Save abcprintf/8642d7075ddc20f5278e62efa4329767 to your computer and use it in GitHub Desktop.
Save abcprintf/8642d7075ddc20f5278e62efa4329767 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/sivahof
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<form>
<div class="form-group">
<label>จำนวนไฟฟ้าที่ใช้</label>
<input type="text" id="elect" value="50">
หน่วย
</div>
<div class="form-group">
<label>ค่าไฟฟ้าหน่วยละ</label>
<input type="text" id="unit" value="10">
บาท
</div>
<button type="button" onclick="calElect()">คำนวณค่าไฟฟ้า</button>
</form>
<div>
จำนวนไฟฟ้าที่ใช้ = 50 หน่วย
</div>
<div>
ค่าไฟฟ้าหน่วยละ = 10 บาท
</div>
<div>
รวมเป็นเงิน = 525 บาท
</div>
<script id="jsbin-javascript">
function calElect() {
var elect = document.getElementById("elect").value;
var unit = document.getElementById("unit").value;
var elect_next = 0; // ค่าไฟฟ้าอัตราก้าวหน้า
var elect_price = 0; // ค่าไฟฟ้า
var elect_price_total = 0; // ค่าไฟฟ้ารวม
if(elect < 40){
elect_next = 2;
}else if(elect <= 100){
elect_next = 5;
}else {
elect_next = 10;
}
elect_price = elect * unit;
elect_price_total = elect_price + (unit * elect_next);
// console.log(elect_price, elect_price_total);
alert("" + elect_price_total);
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">function calElect() {
var elect = document.getElementById("elect").value;
var unit = document.getElementById("unit").value;
var elect_next = 0; // ค่าไฟฟ้าอัตราก้าวหน้า
var elect_price = 0; // ค่าไฟฟ้า
var elect_price_total = 0; // ค่าไฟฟ้ารวม
if(elect < 40){
elect_next = 2;
}else if(elect <= 100){
elect_next = 5;
}else {
elect_next = 10;
}
elect_price = elect * unit;
elect_price_total = elect_price + (unit * elect_next);
// console.log(elect_price, elect_price_total);
alert("" + elect_price_total);
}</script></body>
</html>
function calElect() {
var elect = document.getElementById("elect").value;
var unit = document.getElementById("unit").value;
var elect_next = 0; // ค่าไฟฟ้าอัตราก้าวหน้า
var elect_price = 0; // ค่าไฟฟ้า
var elect_price_total = 0; // ค่าไฟฟ้ารวม
if(elect < 40){
elect_next = 2;
}else if(elect <= 100){
elect_next = 5;
}else {
elect_next = 10;
}
elect_price = elect * unit;
elect_price_total = elect_price + (unit * elect_next);
// console.log(elect_price, elect_price_total);
alert("" + elect_price_total);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment