From db042caeda9049722f9cb09a13e53f01d1ef804f Mon Sep 17 00:00:00 2001 From: Kamrul Islam Shahin <44506464+shahin-cuet@users.noreply.github.com> Date: Tue, 13 Oct 2020 00:13:35 +0600 Subject: [PATCH] fix if else statement in checking items in a list --- 05_Day_Arrays/05_day_arrays.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/05_Day_Arrays/05_day_arrays.md b/05_Day_Arrays/05_day_arrays.md index 3374c12..3a92592 100644 --- a/05_Day_Arrays/05_day_arrays.md +++ b/05_Day_Arrays/05_day_arrays.md @@ -390,22 +390,24 @@ Check an element if it exist in an array. const fruits = ['banana', 'orange', 'mango', 'lemon'] let index = fruits.indexOf('banana') // 0 -if(index != -1){ +if(index === -1) { console.log('This fruit does exist in the array') } else { - console.log('This fruit does not exist in the array') + console.log('This fruit exists in the array') } -// This fruit does exist in the array +// This fruit exists in the array // we can use also ternary here -index != -1 ? console.log('This fruit does exist in the array'): console.log('This fruit does not exist in the array') +index === -1 +? console.log('This fruit does exist in the array') +: console.log('This fruit exists in the array') // let us check if a avocado exist in the array let indexOfAvocado = fruits.indexOf('avocado') // -1, if the element not found index is -1 -if(indexOfAvocado!= -1){ +if(indexOfAvocado === -1) { console.log('This fruit does exist in the array') } else { - console.log('This fruit does not exist in the array') + console.log('This fruit exists in the array') } // This fruit does not exist in the array ```