-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Description
Video 73 Challenge Solution
The following solution was removed from YouTube comments due a glitch or something. I have opened this as an issue.
HTML (index.html)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
</div>
<script src="script.js"></script>
</body>
</html>CSS (style.css)
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap');
* {
margin: 0;
padding: 0;
font-family: 'Inter', sans-serif;
}
.container {
display: flex;
flex-direction: column;
padding: 8px;
margin: 18px;
}
.yt-card {
display: flex;
flex-direction: row;
align-items: center;
border: 1px solid black;
margin-bottom: 8px;
padding: 8px;
border-radius: 8px;
}
.yt-thumbnail {
position: relative;
}
.yt-thumbnail img {
border-radius: 8px;
}
.yt-thumbnail .yt-duration {
position: absolute;
bottom: 6px;
right: 4px;
background-color: #303030;
border-radius: 8px;
padding: 2px;
color: white;
font-weight: 700;
width: 42px;
text-align: center;
font-size: 12px;
}
.yt-details {
display: flex;
flex-direction: column;
margin-left: 18px;
}
.yt-info {
display: flex;
flex-direction: row;
color: gray;
margin-top: 8px;
gap: 4px;
}JavaScript (script.js)
function createCard(title, cName, views, monthsOld, duration, thumbnail) {
let container = document.querySelectorAll('div.container')[0];
if (views >= 1000 && views <= 999999) {
views = Math.floor((views / 1000) * 10) / 10 + 'K'
} else if (views >= 1000000 && views <= 999999999) {
views = Math.floor((views / 1000000) * 10) / 10 + 'M'
} else if (views >= 1000000000) {
views = Math.floor((views / 1000000000) * 10) / 10 + 'B'
}
const str = `<div class="yt-thumbnail">
<img src="http://github.com/%3Cspan%20class="pl-s1">${thumbnail}" alt="">
<span class="yt-duration">${duration}</span>
</div>
<div class="yt-details">
<div class="yt-name">${title}</div>
<div class="yt-info">
<div class="yt-cName">${cName}</div> •
<div class="yt-views">${views}</div> •
<div class="yt-monthsOld">${monthsOld} months old</div>
</div>
</div>`;
let card = document.createElement('div');
card.classList.add('yt-card');
card.innerHTML = str;
container.insertAdjacentElement('beforeend', card);
}
createCard("Introduction to Backend | Sigma Web Dev video #2", "CodeWithHarry", 560000, 7, "31:22", "https://i.ytimg.com/vi/tVzUXW6siu0/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLACwWOixJVrKLFindK92kYMgTcQbw")Solution files attached
video 73.zip
Metadata
Metadata
Assignees
Labels
No labels