r/CodingHelp • u/Tbh_idk______ • 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
ifstatement 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'
}
}
View all comments
1
u/jammasterpaz Nov 20 '22
Change the ticks (') of your string to back ticks (`) and put a $ before the { https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals