Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
896 B
2
Indexable
Never
function examPrep(input) {

    let badGrades = 0;
    let exerciseCounter = 0;
    let sum = 0;
    let lastExercise = '';

    let index = 0;
    let arg = Number(input[index]);

    while (badGrades < arg) {
        index++;
        let exerciseName = input[index];
        let lastExercise = input[index - 2];
        index++;

        let grade = Number(input[index]);
        sum += grade || 0;


        if (grade <= 4) {
            badGrades++;
        }

        if (exerciseName === "Enough") {
            console.log(`Average score: ${sum / exerciseCounter}`);
            console.log(`Number of problems: ${exerciseCounter}`);
            console.log(`Last problem: ${lastExercise}`);
            break;
        }
        exerciseCounter++;
    }


}
examPrep(["3",

    "Money",

    "6",

    "Story",

    "4",

    "Spring Time",

    "5",

    "Bus",

    "6",

    "Enough"])
Leave a Comment