Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Learn to apply your introductory knowledge of HTML, CSS, and JavaScript to build beautiful, real-world components. In this course, you’ll go through the process of developing several complex components, including:
– eBay’s dropdown menu
– Gmail’s auto-validating form
– Google’s main autocomplete enabled search
– Twitter’s infinitely scrolling list
– Medium’s tooltips You’ll learn how to approach common frontend challenges, what questions to ask yourself, how to design solutions once you’ve thought of them, how to debug and work with mistakes, and more.
The end-goal is to empower you to look at anything you see on a website and be able to say, “I can build that!”
Q1. When is it appropriate to hardcode data into HTML?
Q1. Which division of groups is best suited for the submenu?
Q1. Why is the above line wrong?
const HOST = 'server.com/';
function populateCategories(category) {
const activeMenuItemName = activeMenuItem.children[0].innerHTML;
api.get(HOST + 'categories', {category, menuItem: activeMenuItemName}, function(categories) {
let newCategories = '';
for (const category of categories) {
const categoryElement = `
<li class="menu__sub__categories__item">
<a href="#" class="menu__sub__categories__item__link">${category}</a>
</li>
`;
newCategories += categoryElement;
}
const categoriesElement = document.getElementsByClassName(`menu__sub__categories__items--${category}`)[0];
categoriesElement.innerHTML = newCategories;
});
}
function showSubmenu() {
const submenu = document.getElementsByClassName("menu__sub")[0];
submenu.style.display = "block";
populateCategories('top');
populateCategories('additional');
}
function hideSubmenu() {
const submenu = document.getElementsByClassName("menu__sub")[0];
submenu.style.display = "none";
}
let activeMenuItem = null;
function onMenuItemMouseEnter(item) {
if (activeMenuItem) {
activeMenuItem.classList.remove("menu__main__item--active");
}
activeMenuItem = item;
item.classList.add("menu__main__item--active");
showSubmenu();
}
const menuItems = document.getElementsByClassName("menu__main__item");
for (const menuItem of menuItems) {
menuItem.onmouseenter = () => onMenuItemMouseEnter(menuItem)
}
const menu = document.getElementsByClassName("menu")[0];
menu.onmouseleave = hideSubmenu;
// Server
function getCategories(data) {
if (data.category == 'top') {
if (data.menuItem == 'Motors') {
return [
'Car',
'Motorcycle',
'Plane',
'Trucks',
'Wheels'
];
}
if (data.menuItem == 'Fashion') {
return [
'Women\'s tops',
'Men\'s tops',
'Jeans',
'Hats'
];
}
return [
'Server apple',
'Server banana',
'Server pear',
'Server orange'
];
}
if (data.category == 'additional') {
if (data.menuItem == 'Motors') {
return [
'Tires',
'Windshields',
'Ski racks',
'Doors',
'Windows'
];
}
if (data.menuItem == 'Fashion') {
return [
'On sale',
'Red stuff',
'Gucci',
'New Arrivals'
];
}
return [
'Server square',
'Server circle',
'Server oval',
'Server diamond'
];
}
return [];
}
const endpoints = {
"/categories": {
"get": getCategories
}
}
function getFunction(url, data, callback) {
const domain = url.substring(0, url.indexOf("/"));
const endpoint = url.substring(url.indexOf("/"), url.length);
callback(endpoints[endpoint]["get"](data));
}
const api = {
get: getFunction
};
function deactivateMenuItem() {
activeMenuItem.classList.remove("menu__main__item--active");
}
const submenu = document.getElementsByClassName("menu__sub")[0];
submenu.onmouseleave = deactivateMenuItem;
Q1. What scenario would we most likely want the client to cache results?
Q1. Will this work for our development purposes?
Q1. Which edge case will not be fully tested with this server code?
Q1. Why did we get this output?
Q1. Would setting the width a hardcoded value of 10rem
for the element in Javascript be a better option?
top
and left
set before we put it on the DOM, and the only way to do that is to have the width in Javascript.rem
is only understood if defined in CSS.Q1. Why do you think this is happening?
top
and left
positionQ1. Which of the following is not a useful test?
false
.Q1. How do you know which validation rule to apply?
signup__field__input--firstname
, we know to apply the name validationaria-label
Q1. Which regex will enforce an input with the rule that only allows numbers of length 4?
/^{0-9}+$/
/^[0-9]+4$/
/^[4]{0-9}$/
/^[0-9]{4}$/
Q1. Which grouping is reasonable?
Q1. What information would you add to request tweets so that there’s enough to satisfy our requirements?
lastTweetId
– the unique ID of the tweet that was at the bottom of the resultstimeLastRequested
– the timestamp to the millisecond of when the last request waslistOfTweetIds
– the list of tweet IDs that we haveQ1. Which change do you think works best?
const DEFAULT_PAGE_SIZE = 5;
const DEFAULT_SORT_ORDER = 'recent';
const States = {
PENDING: 'pending',
READY: 'ready',
BACKOFF: 'backoff'
};
let componentState = States.READY;
function isComponentPending() {
return componentState === States.PENDING;
}
function setPending() {
componentState = States.PENDING;
document.body.appendChild(loadingElement);
}
function setReady() {
componentState = States.READY;
document.body.removeChild(loadingElement);
}
function setBackoff() {
componentState = States.BACKOFF;
document.body.removeChild(loadingElement);
}
let lastTweetId = null;
const loadingElement = document.createElement('div');
// Give it the same style
loadingElement.classList.add('tweet');
loadingElement.innerHTML = `
Here I am... Loading...
<img class="loading__image" src="http://educative.io/udata/1m5lkL7p9Q0/dog.jpeg" />
`;
function onNewTweets(data) {
if (data.length <= 1) {
setBackoff();
setTimeout(() => setReady(), 2000);
} else {
setReady();
let tweetsHTML = '';
for (const tweetResponse of data) {
const tweet = createTweet(tweetResponse.tweet);
tweetsHTML += tweet;
lastTweetId = tweetResponse.id;
}
document.body.innerHTML += tweetsHTML;
}
}
function hydrate() {
const params = {
pageSize: DEFAULT_PAGE_SIZE,
sortOrder: DEFAULT_SORT_ORDER
}
api.get(HOST + 'tweets', params, onNewTweets);
setPending();
}
loadTestData();
hydrate();
function onScroll(event) {
if (isComponentPending()) {
return;
}
const scrolledTo = window.innerHeight + window.pageYOffset;
const scrollLimit = document.body.offsetHeight;
const scrollThreshold = 30;
if (scrollLimit - scrolledTo <= scrollThreshold && componentState != 'backoff') {
const params = {
pageSize: DEFAULT_PAGE_SIZE,
sortOrder: DEFAULT_SORT_ORDER,
lastTweetId
}
api.get(HOST + 'tweets', params, onNewTweets);
setPending();
}
}
window.addEventListener('scroll', onScroll);
</script>
Q1. Which idea doesn’t seem possible?
I hope this Intermediate JavaScript: Building Frontend Components Educative Quiz Answers would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>