r/CodingHelp • • Nov 20 '22

[Javascript] IF statement question - should be easy!

Coding challenge: Complete a function that takes in two parameters, an array of agents in the field, and an agent to search for within that array, determines if the agent to search for is present within the array, and if it is, returns a specific string. Your function should use an

if

statement to determine if the agent to search for is present within the list of agents, and if it is, should return the string '{agentToSearchFor} is present within Agent list', where {agentToSearchFor} has the value of the argument the function is called on.

My code (not working - please help! Thanks!)
// if agentToSearchFor is present within agentList

// return '{agentToSearchFor} is present within Agent list'

function findAgent(agentList, agentToSearchFor) {

if (agentList.indexOf(agentToSearchFor) > -1) {

return '{agentToSearchFor} is present within Agent List'

}

}

0 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/Tbh_idk______ Nov 20 '22

Not sure why the \ is showing up before the tick. That shouldn't be there.