Advertisement
3vo

Problem 2. Bonus Score

3vo
Oct 25th, 2022
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Write a program that applies bonus score to given score in the range [1…9] by the following rules: * If the score is between 1 and 3,
  2. // the program multiplies it by 10. * If the score is between 4 and 6, the program multiplies it by 100. * If the score is between 7 and 9,
  3. // the program multiplies it by 1000. * If the score is 0 or more than 9, the program prints “invalid score”.
  4. //
  5. // Examples:
  6. // score/result
  7. // 2    20
  8. // 4    400
  9. // 9    9000
  10. // -1   invalid score
  11. // 10   invalid score
  12. let input = ['10'];
  13. let print = this.print || console.log;
  14. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  15. //Get the score in range [1 to 9]
  16. let score = +gets();
  17. //If the score is between 1 and 3,
  18. //the program multiplies it by 10
  19. //If the score is between 4 and 6,
  20. //the program multiplies it by 100.
  21. //If the score is between 7 and 9,
  22. // the program multiplies it by 1000.
  23. //If the score is 0 or more than 9
  24. //the program prints “invalid score”
  25. if(score >=1 && score <= 3){
  26.     console.log(score * 10);
  27. } else if(score >= 4 && score <= 6) {
  28.     console.log(score * 100);
  29. }else if(score >= 7 && score <= 9) {
  30.     console.log(score * 1000);
  31. }else if(score >= 7 && score <= 9) {
  32.     console.log(score * 1000);
  33. } else {
  34.     console.log(`invalid score`);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement