Birthday Cake Candles | HackerRank

Hi All, the below code is for birthday candle problem in hackerrank. It is working fine in visual studio code but throws error in hackerrank. if anyone knows what is the problem with the code let me know…

function birthdayCakeCandles(candles) {
let max = Math.max(...candles)
let count=0
for(let i=0;i<candles.length;i++){
    if(candles[i]===max){
      count++
    }
}console.log(count)
}
birthdayCakeCandles([1,3,2,3])

output: The maximum height candles are of height "3 units". There are two of them, so 2 should be the output.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

you may want to check what’s your function output is

it is undefined

it is undefined only in hackerrank, but in visual studio code the output is 2

What do you mean by “the output”? What is your function’s return value? The return value is the only “output” for a function.

Thanks Jeremy. The count is the return value.

Where do you return the count?

I forgot to return the count

1 Like

2 posts were split to a new topic: Hackerrabk question - rounding grades