Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

just a simple program that prompts the user to enter their favorite ice cream ag

ID: 3546308 • Letter: J

Question

just a simple program that prompts the user to enter their favorite ice cream against an array.  if there is a match, say which number in the array and say it is a match.  if there is no match, the flavor is not in the top " " of the array.


var ice=["chocolate", "vanilla", "strawberry"];


var flavor=prompt("what is your favorite ice cream?");


var compare= function (flavor)

{

for(i=ice.length; i++)

{

if(flavor===ice[i])

{

document.write (flavor + " is number " + i+1);

}

}

document.write (flavor + " is not a favorite");

};

Explanation / Answer

Hi Your program is here: http://pastebin.com/KfKfyrL0

Let me know if you need more help.

You need to initialize i = 0 and break the loop once u find the flavor. Also display the not favorite message only if the whole array does not have the value.

Please rate.

Thanks