Need help with exiting a for loop

Hi, so I’m doing the JS course here at freecodecamp, but I’m also doing a Udemy course alongside it. For this Udemy course, we made a simple facebook type program that prompts your name and password and then shows you a timeline. As I had already gone throught the basic JS section here, I wanted to add some things to this program and try out my knowledge of for loops.

I’m posting the code below. The idea is that the browser prompts your name and password and then uses a for loop to compare them with the usernames and passwords in the database array. When it finds a match it then uses another for loop to display the proper “feed” from the feed array.

And it works! I was super happy about that. The problem is I can’t figure out what to do if the name and password don’t match any in the user database. I want to display an alert that alerts that the name and password don’t match. But I’ve put it in every position I can think of without any success. If I put it after the initial if statement, which made the most sense to me, then it exits the loop after the first loop if i = 0 doesn’t match anything.

I’ve tried different if and else statements in different positions to no avail for the past few hours, and I decided it was time to ask. I’m sure it’s super simple, but my brain can’t see anything past what I’ve already tried at this point!

var feedDanny = {
		friend: "Lola",
		timeline: "Murray!" 
	};

var feedLola = {
		friend: "Simon",
		timeline: "Mountains!"
	};

var feedPaula = {
		friend: "Dixie",
		timeline: "Lesbians!"
	}

var user = {
	name: "Danny",
	pass: "yellow",
	newsfeed: feedDanny
};

var user1 = {
	name: "Lola",
	pass: "green",
	newsfeed: feedLola
};

var user2 = {
	name: "Paula",
	pass: "blue",
	newsfeed: feedPaula
};

var database = [user, user1, user2];
var feed = [feedLola, feedDanny, feedPaula];


var userNamePrompt = prompt("What's your user name?");
var passwordPrompt = prompt("What's your password?");

function signIn(userName, password) { 
	for (var i = 0; i < database.length; i++) {	console.log(i);
		if (userName === database[i].name
		 && password === database[i].pass) {
			for (var j = 0; j < feed.length; j++) { console.log("j" + j);
				if (feed[j] === database[i].newsfeed) { 
					alert(feed[j].friend + ": " + feed[j].timeline);
					break;
				}
		 	}
  break;}
}
} 

signIn(userNamePrompt, passwordPrompt);

Hello,

This code will solve your problem.

function signIn(userName, password) 
{ 
    var i;
	for (i = 0; i < database.length; i++) 
	{	
	    console.log(i);
		if (userName === database[i].name && password === database[i].pass) 
		{
			for (var j = 0; j < feed.length; j++) 
			{ 
			    console.log("j" + j);
				if (feed[j] === database[i].newsfeed) 
				{ 
					alert(feed[j].friend + ": " + feed[j].timeline);
					break;
				}
		 	}
            break;
		}
    }
    
    if(i == database.length)  // This means no match is found.
       console.log("Your message here");
}

Yep, that does it! Simple solution, but not one I would have thought of. Thank you!