so I'm working on my first HTML-CSS-JS-jQuery project. I have to make a simple tweeter, it's just for learning. One of the features is that the app should render a user's feed with only his tweets, if when at the home feed, you click over a users nametag. I don't really have much experience coding, so It might be a small data type error and I can't notice it, thanks for the help!
This is my renderFeed function:
var renderFeed = function (user) {
if (user === 'undefined') {
var index = streams.home.length - 1;
var tweet = streams.home[index];
} else {
var index = streams.users[user].length - 1;
var tweet = streams.users[user][index];
}
while (index >= 0) {
var $tweet = $('<div class="tweet"></div>');
$('#feed').append($tweet);
var formattedDate = jQuery.timeago(tweet.created_at);
var $profilePhoto = $('<img src="' + tweet.profilePhotoURL + '" class="profile-photo">');
var $username = $('<span class="username"></span>');
var $message = $('<p class="message"></p>');
var $timestamp = $('<span class="timestamp">' + formattedDate + '</span>');
var $comment = $('<i class="fas fa-comment comment"></i>');
var $retweet = $('<i class="fas fa-retweet retweet"></i>');
var $like = $('<i class="fas fa-heart like"></i>');
var $share = $('<i class="fas fa-share-alt share"></i>');
$message.text(tweet.message);
$username.text('@' + tweet.user);
$($tweet).append($profilePhoto);
$($tweet).append($username);
$($tweet).append($message);
$($tweet).append($timestamp);
$($tweet).append($comment);
$($tweet).append($retweet);
$($tweet).append($share);
$($tweet).append($like);
index -= 1;
}
}
When passed a user, it should then access an array that contains each tweet from that user. It appends a tweet with all its UI components and renders the proper feed.
This is the error I get when running this code:
Cannot read property 'length' of undefined