efthaqur

assignment04

Aug 14th, 2025
66
0
22 hours
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.21 KB | Source Code | 0 0
  1. /**
  2.  *
  3.  * Problem 01
  4.  */
  5.  
  6. function totalFine(fare){
  7.     if(fare != 0 && fare > 0 && typeof fare !='string'){
  8.         penalty = fare + fare*0.2 + 30;
  9.         return penalty;
  10.     }
  11.     else return 'Invalid';
  12. }
  13.  
  14.  
  15.  
  16. /**
  17.  *
  18.  * Problem 02
  19.  */
  20.  
  21. function onlyCharacter(str){
  22.     if(typeof str === 'string' && Array.isArray(str) == false && typeof str !=='boolean'){
  23.         text = str.replaceAll(' ', '').toUpperCase();
  24.         return text;
  25.     }
  26.     else return 'Invalid';
  27. }
  28.  
  29.  
  30. /**
  31.  *
  32.  * Problem 03
  33.  */
  34.  
  35. function bestTeam(player1, player2){
  36.         if(typeof player1 !== 'object' || typeof player2 !== 'object' ){
  37.             console.log("Invalid");
  38.         }
  39.         else if(player1.foul+player1.cardY+player1.cardR < player2.foul+player2.cardY+player2.cardR){
  40.             console.log(player1.name +' rocks');
  41.         }
  42.         else if(player1.foul+player1.cardY+player1.cardR == player2.foul+player2.cardY+player2.cardR){
  43.             console.log('Tie');
  44.         }
  45.         else {
  46.             console.log(player2.name +' rocks');
  47.         }
  48.  
  49. }
  50.  
  51. const team01 = {name:"Germany", foul:10, cardY:1, cardR:1};
  52. const team02 = {name:"France", foul:10, cardY:2, cardR:1};
  53.  
  54. bestTeam(team01, team02);
  55.  
  56. /**
  57.  *
  58.  * Problem 04
  59.  */
  60.  
  61. function isSame(arr1, arr2){
  62.     if(Array.isArray(arr1) == false || Array.isArray(arr2) == false){
  63.         return 'Invalid';
  64.     }
  65.     if(arr1.length !== arr2.length){
  66.             return false;
  67.         }
  68.  
  69.     for(let i=0; i<=arr1.length; i++){
  70.         if(arr1[i]!==arr2[i])
  71.             return false;
  72.        
  73.     }
  74.    
  75.     return true;
  76.    
  77. }
  78.  
  79.  
  80.  
  81. /**
  82.  * Problem 05
  83.  */
  84.  
  85. function resultReport(marks) {
  86.     if(Array.isArray(marks)==false){
  87.         return 'Invalid';
  88.     }
  89.     else {
  90.         let score =0, pass =0, fail =0;
  91.         for(let i=0; i<marks.length; i++){
  92.             if(marks[i]<40){
  93.                 fail++;
  94.             }
  95.             if(marks[i]>40){
  96.                 pass++;
  97.             }
  98.             score = score +marks[i];
  99.         }
  100.         score = score/marks.length;
  101.        isNaN(score) ? score = 0 : score;
  102.         const result = { finalScore: Math.round(score), pass:pass, fail:fail}
  103.         return result;
  104.     }
  105.    
  106. }
  107.  
  108.  
  109.  
  110.  
Advertisement
Add Comment
Please, Sign In to add comment