From Evernote: |
더치페이 계산기 |
<!DOCTYPE html>
<html lang="ko" >
<head>
<meta charset="utf-8" >
<title> go Dutch Calculator </title>
<script src="goDutch.js" ></script>
</head>
<body>
<h1> Go_Dutch_Calculator</h1 >
<P> Amount : <input type="text" id= "amount"></P >
<P> number : <input type="text" id= "num"></P >
<P> money to pay : <input type="button" value="calculate" onclick="getResult();" ></P>
<p id= "result"></p >
</body>
</html>
|
function getResult(){
var amount = document.getElementById('amount' ).value;
var num = document.getElementById('num' ).value;
var unit = 100;
var x = Math.floor((amount / num) / unit) * unit;
var y = amount - (x * num);
var xx = Math.ceil((amount / num) / unit) * unit;
var yy = (xx * num) - amount;
//console.log(xx);
//console.log(yy);
document.getElementById( 'result').innerHTML =
'한사람당' + x + '원이면' + y + '원 부족합니다.' + '한사람당' + xx + '원이면' + yy + '원 남습니다.';
}
|
No comments:
Post a Comment