scrimba
Frontend Career Path
Essential JavaScript concepts
Twitter Clone
Like a tweet part 2: data attributes
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Like a tweet part 2: data attributes
AboutCommentsNotes
Like a tweet part 2: data attributes
Expand for more info
index.js
run
preview
console
import { tweetsData } from './data.js'
const tweetInput = document.getElementById('tweet-input')
const tweetBtn = document.getElementById('tweet-btn')

tweetBtn.addEventListener('click', function(){
console.log(tweetInput.value)
})

function getFeedHtml(){
let feedHtml = ``
/*
Challenge:
1. Add data attributes to each of the <i> tags. You can call
them 'reply', 'like', and 'retweet’.
2. Each data attribute should hold the tweet's uuid.
*/

tweetsData.forEach(function(tweet){
feedHtml += `
<div class="tweet">
<div class="tweet-inner">
<img src="${tweet.profilePic}" class="profile-pic">
<div>
<p class="handle">${tweet.handle}</p>
<p class="tweet-text">${tweet.tweetText}</p>
<div class="tweet-details">
<span class="tweet-detail">
<i class="fa-regular fa-comment-dots"></i>
${tweet.replies.length}
</span>
<span class="tweet-detail">
<i class="fa-solid fa-heart"></i>
${tweet.likes}
</span>
<span class="tweet-detail">
<i class="fa-solid fa-retweet"></i>
${tweet.retweets}
</span>
</div>
</div>
</div>
</div>
`
})
return feedHtml
}

function render(){
document.getElementById('feed').innerHTML = getFeedHtml()
}

render()

Console
/index.html
-2:20