Section 2.2 CODDING CHALLENGE 1 ()

CODDING CHALLENGE 1

John and Mike both play backetball in different teams. In the lastest 3 games, John’s team scored 89, 120 and 130 points, while Mike’s team scored 116, 96 and 123 point.

  1. Calculate the average score for each team.
  2. Decide which teams wins in average (hightest average score), and print the winner to the console. Also include the average score in the output.
  3. Then change the scores to show different winners. Don’t forget to take into account there might be a draw (the same average score)
  4. EXTRA: Mary also plays basketball, and her team scored 97, 134 and 105 points. Like before, log the average winner to the console. HINT: you will need the && operator to take the decision.
    if you cannot solve this one, just watch the solution, it’s no problem.
  5. Like before, change the scores to generate different winners, keeping in mind there might be draws.

// 1.

var scoreJohn = (89 + 120 + 103) / 3;
var scoreMike = (116 + 94 + 123) / 3;
console.log("scoreJohn: " + scoreJohn, "scoreMike: " + scoreMike);

// 2.

if (scoreJohn > scoreMike) {
    console.log("John's team wins with " + scoreJohn + " points!")
} else if (scoreMike > scoreJohn) {
    console.log("Mike's team wins with " + scoreMike + " points!")

} else {
    console.log("There is a draw!")
}

// 3.

var scoreJohn = (110 + 120 + 103) / 3; //var scoreJohn = (111 + 120 + 103) 
var scoreMike = (116 + 94 + 123) / 3;
console.log("scoreJohn: " + scoreJohn, "scoreMike: " + scoreMike);

if (scoreJohn > scoreMike) {
    console.log("John's team wins with " + scoreJohn + " points!")
} else if (scoreMike > scoreJohn) {
    console.log("Mike's team wins with " + scoreMike + " points!")

} else {
    console.log("There is a draw!")
}

// 4.

var scoreJohn = (89 + 120 + 103) / 3; 
var scoreMike = (119 + 94 + 123) / 3; //var scoreMike = (116 + 94 + 123) / 3; Draw
var scoreMary = (97 + 134 + 105) / 3;

console.log("scoreJohn: " + scoreJohn, "scoreMike: " + scoreMike, "ScoreMary: "+ scoreMary + ". ");

if (scoreJohn > scoreMike && scoreJohn > scoreMary) {
    console.log("John's team wins with " + scoreJohn + " points!")
} else if (scoreMike > scoreJohn && scoreMike> scoreMary) {
    console.log("Mike's team wins with " + scoreMike + " points!")

} else if (scoreMary > scoreJohn && scoreMary> scoreMike) {
    console.log("Mary's team wins with " + scoreMary + " points!")

} else {
    console.log("There is a draw!")
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值