Created
April 1, 2021 17:20
-
-
Save IacovColisnicenco/6cec56185964eed9678aa67c45ebaa09 to your computer and use it in GitHub Desktop.
searchElem, indexOf, function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let arr = [1, 2, 3, 4]; | |
let arg = prompt("input your number", "0"); | |
if (arg != null) { | |
searchElem(arg); | |
} else { | |
console.log("Cancel was pressed"); | |
} | |
function searchElem(arg){ | |
let res = arr.indexOf(+arg); | |
if (res == -1) { | |
console.log("Num not found"); | |
} else { | |
console.log(res); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment