从宿舍转换为便士

时间:2012-02-09 15:24:03

标签: javascript

我坚持在JS上制作一个模块,用于从宿舍转换为便士,这是我到目前为止所得到的。我错过了什么?

<html>
<head>
<title>Bicycle</title>
<script type="text/javascript">
//Program: Problem 5
//Purpose: calculate the number of quarters a person will get in return when they enter the number of pennies they have
//Author: Zach
//Date last modified: 2/9/12
var entrmoney = ""
var totnum = "The total number of quarters needed is "
var totcents = "left over"
entrmoney = prompt("How much money do you want to turn into Quarters,enter in pennies?")

document.write(totnum + + totcents)

</script>
</head>
<body>
</body>
</html>

2 个答案:

答案 0 :(得分:2)

我猜你需要对输入的便士做一些计算。

JSFiddle似乎已经失败所以我没有尝试过代码,但是这样的事情应该计算出宿舍的数量和剩下的便士:

var entrmoney = parseInt(prompt("How much money do you want to turn into Quarters,enter in pennies?"), 10);
var totnum = "The total number of quarters needed is "
var totcents = "left over"
var quarters = Math.floor(entrmoney / 25);
var pennies = entrmoney % 25; 

document.write(totnum + quarters + totcents + pennies)

答案 1 :(得分:1)

忘记转换尝试

<html>
<head>
<title>Bicycle</title>
<script type="text/javascript">
//Program: Problem 5
//Purpose: calculate the number of quarters a person will get in return when they enter the number of pennies they have
//Author: Zach Salih
//Date last modified: 2/9/12
var entrmoney = "";
var totnum = "The total number of quarters needed is ";
var totcents = "left over";
entrmoney = prompt("How much money do you want to turn into Quarters,enter in pennies?");
entrmoney = entrmoney/25;
document.write(totnum + entremoney + totcents);

</script>
</head>
<body>
</body>
</html>