+ 1

Why its getting timed out???

function main() { let products = new Set([ "dumbbells", "barbell", "t-shirt", "swim short", "gloves", "training apparatus", "goggle" ]); var count = 0; while(count<3){ var itemType = readLine(); products.add(); //add the item to the set } //calculate and output the count of item types console.log(products.size); } Output : Execution is timed out!

20th Jan 2022, 11:08 AM
Evgeny Sergeev
Evgeny Sergeev - avatar
4 ответов
+ 1
You are not updating count value. So count<3 is always true.. then it's an infinite while loop... Update count by ' count++; ' after reading input. and Evgeny Sergeev also you need to add input to set by products.add(itemType) ; edit: pls edit tag java to javascript.....
20th Jan 2022, 11:12 AM
Jayakrishna 🇮🇳
+ 1
You forgot to increment variable <count> in the while...loop. Due to that the loop goes infinitely.
20th Jan 2022, 11:11 AM
Ipang
+ 1
You are not incrementing the counter inside the while loop
20th Jan 2022, 11:11 AM
Adi Nath Bhawani
Adi Nath Bhawani - avatar
0
Thanks everyone it worked ! I though count <3 cant go infinite beacuse stops on 2, is it correct?
20th Jan 2022, 11:17 AM
Evgeny Sergeev
Evgeny Sergeev - avatar