Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * Problem 01
- */
- function totalFine(fare){
- if(fare != 0 && fare > 0 && typeof fare !='string'){
- penalty = fare + fare*0.2 + 30;
- return penalty;
- }
- else return 'Invalid';
- }
- /**
- *
- * Problem 02
- */
- function onlyCharacter(str){
- if(typeof str === 'string' && Array.isArray(str) == false && typeof str !=='boolean'){
- text = str.replaceAll(' ', '').toUpperCase();
- return text;
- }
- else return 'Invalid';
- }
- /**
- *
- * Problem 03
- */
- function bestTeam(player1, player2){
- if(typeof player1 !== 'object' || typeof player2 !== 'object' ){
- console.log("Invalid");
- }
- else if(player1.foul+player1.cardY+player1.cardR < player2.foul+player2.cardY+player2.cardR){
- console.log(player1.name +' rocks');
- }
- else if(player1.foul+player1.cardY+player1.cardR == player2.foul+player2.cardY+player2.cardR){
- console.log('Tie');
- }
- else {
- console.log(player2.name +' rocks');
- }
- }
- const team01 = {name:"Germany", foul:10, cardY:1, cardR:1};
- const team02 = {name:"France", foul:10, cardY:2, cardR:1};
- bestTeam(team01, team02);
- /**
- *
- * Problem 04
- */
- function isSame(arr1, arr2){
- if(Array.isArray(arr1) == false || Array.isArray(arr2) == false){
- return 'Invalid';
- }
- if(arr1.length !== arr2.length){
- return false;
- }
- for(let i=0; i<=arr1.length; i++){
- if(arr1[i]!==arr2[i])
- return false;
- }
- return true;
- }
- /**
- * Problem 05
- */
- function resultReport(marks) {
- if(Array.isArray(marks)==false){
- return 'Invalid';
- }
- else {
- let score =0, pass =0, fail =0;
- for(let i=0; i<marks.length; i++){
- if(marks[i]<40){
- fail++;
- }
- if(marks[i]>40){
- pass++;
- }
- score = score +marks[i];
- }
- score = score/marks.length;
- isNaN(score) ? score = 0 : score;
- const result = { finalScore: Math.round(score), pass:pass, fail:fail}
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment