Here is the issue that needs to be addressed:
The task is to find a number greater than 15 from a list of numbers. If no number meets this criteria, print -1.
Input Description: 0<n<100 Input consists of a number n followed by n numbers on separate lines
Output Description: Print the number greater than 15 or -1 if none are found
Sample Input :
3 5 7 4
Sample Output :
-1
This is my approach to solving it:
var n = 3
var nums = [5, 7, 4]
for (var i of nums){
if (i > 15) {
console.log(i)
} else{
console.log(-1)
}
}
However, the output I'm getting is:
-1
-1
24
I would like to only display either 24
or -1
if there are no numbers greater than 15
. Can someone kindly provide a detailed explanation on how to correct this?