2012-02-09 31 views
-2

我被困在一個模塊化的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> 
+3

有什麼問題,有什麼不行? – 2012-02-09 15:25:23

+0

我沒有看到任何計算正在進行? – 2012-02-09 15:26:13

+0

我不確定它需要的計算。 – user1199777 2012-02-09 15:28:05

回答

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) 
+0

我該如何解釋它說的左邊?假設你換算了28便士,我怎麼會這麼說:「需要的宿舍總數是___剩下的」? – user1199777 2012-02-09 15:36:50

+0

這是在它的外觀解決方案。模數運算符處理它。 – 2012-02-09 15:38:44

+0

似乎沒有給我一個輸出與「所需的宿舍總數是和剩下的是」 – user1199777 2012-02-09 15:39:55

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> 
+0

未從中獲得輸出。 :S – user1199777 2012-02-09 15:29:54

+0

另外,如果用戶輸入28美分或什麼?應該有剩餘嗎? – 2012-02-09 15:30:45

+0

是的,它會說剩下的美分。 – user1199777 2012-02-09 15:31:30