Hackerrank error when running code

Hi, I have been trying some coding challenges at hackerrank and I keep getting an error message when trying to run the code. The funny thing is that the error message has to do with something which was already prewritten in hackerank. I appreciate any help I can get.

I will paste the code and the error message.

'use strict';

const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', function() {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

function readLine() {
    return inputString[currentLine++];
}

// Complete the breakingRecords function below.
function breakingRecords(scores) {
let Min=scores[0];
let Max=scores[0];
let minRecord=0;
let maxRecord=0;
let i;
for (i=1; i<scores.length; i++){
    if (scores[i]<Min) {
        Min=scores[i];
        minRecord+=1;
    }
    else if (scores[i]>Max) {
        Max=scores[i]
        maxRecord+=1;
    }
    console.log(maxRecord+" "+minRecord);
}


}

function main() {
    const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

    const n = parseInt(readLine(), 10);

    const scores = readLine().split(' ').map(scoresTemp => parseInt(scoresTemp, 10));

    const result = breakingRecords(scores);

    ws.write(result.join(' ') + '\n');

    ws.end();
}

Error message
image

Hi there.

It looks like you aren’t returning any value from your function breakingRecords(). By default, when a JavaScript function does not have a return statement, the return value is undefined.

Does that help clarify what’s happening?

Right, the error is popping up in the prewritten code but that is because your code isn’t giving it what it needs.

We read that error and understand that it is telling us that result is undefined which immediately sent Jeremy and me to look at breakingRecords to find the problem.

Thank you @JeremyLT.

Thank you @kevinSmith. :smiley: