我是一名完整的编程初学者,我需要一些帮助。我正在做一个运动,我们有3名球员。每个人都必须输入身高和年龄。然后根据身高+ 5 *年龄的总分来决定获胜者。我的程序有效,但我的计算错误(和更高)。 所以举个例子。让我们说heightJohn = 10和ageJohn = 1.这应该意味着约翰总数是15吗?如果我在没有提示的情况下分配10和1,则totalJohn确实是15.但是当我使用提示时,我的控制台显示总计约翰= 105.我真的不明白为什么和为什么?有人可以启发我,我无法弄清楚我做错了什么。
let heightJohn = prompt("What is Johns height?");
let ageJohn = prompt("What is Johns age?");
let heightBob = prompt("What is Bobs height?");
let ageBob = prompt("What is Bobs age?");
let heightMichael = prompt("What is Michaels height?");
let ageMichael = prompt("What is Michaels age?");
let totalJohn = (heightJohn + 5 * ageJohn);
let totalBob = heightBob + 5 * ageBob;
let totalMichael = heightMichael + 5 * ageMichael;
console.log(ageJohn);
console.log(heightJohn);
console.log(totalJohn);
console.log(totalBob);
console.log(totalMichael);
if(totalJohn > totalBob && totalJohn > totalMichael) {
console.log("John is a winner with the score of " + totalJohn)
} else if(totalBob > totalJohn && totalBob > totalMichael) {
console.log("Bob is a winner with the score of " + totalBob)
} else if(totalMichael > totalJohn && totalMichael > totalBob) {
console.log("Michael is a winner with the score of " + totalMichael)
} else if(totalJohn === totalBob === totalMichael) {
console.log("Its a draw with the score of " + totalMichael)
} else {
console.log("Wrong input");
}