Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function graduation(input) {
- let name = input[0];
- let gradeNum = 0;
- let index = 1;
- let fail = 0;
- let sum = 0;
- while (gradeNum !== 12) {
- let score = Number(input[index++]);
- if (score < 4) {
- fail++;
- if (fail === 2) {
- break;
- }
- } else {
- sum += score;
- }
- gradeNum++;
- }
- if (fail === 2) {
- console.log(`${name} has been excluded at ${gradeNum} grade`);
- } else {
- console.log(`${name} graduated. Average grade: ${((sum / 12)).toFixed(2)}`);
- }
- }
- РEШЕНИЕ СЪС SHIFT И ТЕРНАРЕН ОПЕРАТОР:
- function Graduation(input) {
- let name = input.shift();
- let gradeNum = 0;
- let fail = 0;
- let sum = 0;
- while (input.length !== 0){
- let score = Number(input.shift());
- score < 4? fail++ : sum += score;
- if (fail === 2) {
- break;
- }
- gradeNum++;
- }
- console.log(fail === 2? `${name} has been excluded at ${gradeNum} grade`
- : `${name} graduated. Average grade: ${((sum / 12)).toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement