lundi 31 août 2020

Point System for Hunting Game

Hi friend i have a problem when solving our teacher assignment. Here is the problem:

You are tasked for implementing point system for your company upcoming hunting game. There is a rule for the game:

Point bracket

  1. Bracket total kill 10 point multiplier x1
  2. Bracket total kill 20 point multiplier x2
  3. Bracket total kill 30 point multiplier x3
  4. Bracket total kill 40 point multiplier x4
  5. Bracket total kill 50 point multiplier x5
  6. Bracket total kill above 50 point multiplier x6

Point bracket explanation: *if total kill less or the same than 10, point will be 10 *if total kill between 10 and 20, point will be 2x of total kill between 10 and 20, plus 1x of 10 total kill

  • if total kill between 20 and 30, point will be 2x of total kill between 10 and 20, plus 3x of total kill over 20, plus 1x of 10 total kill
  • if total kill above 30, point will be 2x of total kill between 10 and 20, plus 3x of total kill between 20 and 30, plus 4x total kill over 30, plus 1x of 10 total kill
  • and so on

Ex:

  1. total kill 10, point 10
  2. total kill 27, point 51
  3. total kill 33, point 72
  4. total kill 120, point 570
  5. total kill 60, point 210

I have tried to code it in js, but i think there is some missing logic. can you help me ?

function calculatePoint(totalKill){
    if(totalKill <= 10){
        return 10;
    } else if ( totalKill >= 10 && totalKill <=20){
        return 2*totalKill + 1*10*totalKill;
    } else if ( totalKill>=20 &&  totalKill <=30){
        return 3*totalKill + 1*10*totalKill;
    } else if (totalKill>=30){
        return 2*totalKill + 3*totalKill + 4*totalKill+1*10*totalKill;
    } 
}

Aucun commentaire:

Enregistrer un commentaire