JavaScriptmas 2023 – Week 2
Tis the season! JavaScriptmas is right here once more! JavaScriptmas is a FREE annual festive coding occasion hosted by the web coding faculty Scrimba, consisting of 24 every day coding challenges, prizes, and extra!
JavaScriptmas 2023
What is JavaScriptmas?
JavaScriptmas is a FREE annual occasion comprising 24 coding challenges hosted by the web coding faculty Scrimba. Most of the coding challenges are JavaScript, however this yr, there will likely be a number of CSS challenges, and a few utilizing AI instruments! 🎄
What degree of coder do it’s good to be to take part?
Even if you’re beginning to be taught JavaScript, you’ll be able to take part. For hints, you’ll be able to faucet into the neighborhood, and naturally, you’ll be able to all the time use Google that will help you get to your resolution. There may also be Discord channels for the challenges, in addition to for FAQs. You also can try the subject in Scrimba’s discussion board. 💻
JavaScriptmas prize guidelines
-
Each day, you’ll be able to full the problem by midnight UTC, and share your VALID/working resolution on Twitter/X for an opportunity to win a prize! (You can simply publish your submission through the share resolution button in your Scrim).
-
Take half in Santa’s Code Review Workshop by choosing a JavaScriptmas entry on X/Twitter, doing a code evaluation, and sharing it as a reply publish.
-
Attend the JavaScriptmas YouTube Livestream on Dec 24 for an opportunity to win a Mackbook Air M2
JavaScriptmas prizes
The prizes include 24 Annual Scrimba Pro subscriptions value $200, 5 $100 winners for giving a code evaluation of one other participant’s entry, and a grand prize winner awarded a Mackbook Air M2 value $1,100! All winners will likely be introduced through the JavaScriptmas YouTube Livestream occasion on December twenty fourth. 🎁
JavaScriptmas financial savings
In addition to prizes, be looking out for financial savings with low cost costs on their paid programs! If you are excited by taking a paid course from Scrimba, you’ll want to use the low cost code supplied: https://scrimba.com/pricing?coupon=Michael-Larocca-Discount-2023#be part of. (Valid for an extra 10% off semester and annual plans. Expires on July thirty first, 2024) 💸
Note: Prizes are restricted to at least one per particular person
❄Community highlights❄
In the spirit of the festive vacation season, I take pleasure in that includes others’ works in the neighborhood highlights part of my JavaScriptmas articles! I will likely be looking X/Twitter, LinkedIn, and the Scrimba Discord channel for "excellent" submissions by fellow individuals to function! 🎉
My options
Throughout the JavaScriptmas occasion, I’ll take part in all 24 coding challenges and doc my detailed options! 💻
❄Community highlights❄ ⬇
Alina (@disc0night)
Alina tackled the Jeopardy Card Flip problem with aptitude, designing it to resemble the precise Jeopardy sport board! This inventive contact significantly enhanced the flipping card impact, making the venture really feel such as you’re watching and even collaborating in an actual sport of Jeopardy! Excellent work, Alina!
Wojciech Kasprzak (@kawojtek94)
Wojciech took inventive liberty for the Rockin’ Around jukebox problem and created a working vinyl document participant as an alternative! Choose the vinyl document you wish to hearken to and click on on the tonearm. The tonearm strikes onto the document utilizing CSS animation, and the vinyl document chosen performs! Click on the tonearm once more to cease the music, and watch it animate off the document to its resting place. You can then proceed to pick out and play the opposite vinyl records. Great job, Wojciech!
Austin Edmondson
While looking for JavaScriptmas participant posts on social media, I got here throughout Austin’s posted resolution on LinkedIn. What caught my consideration was his distinctive technique of sharing his coding options. Instead of posting a hyperlink to the completed coding resolution as others do, Austin is creating Scrimba screencasts, wherein he records himself discussing his total thought course of as he tackles every problem. This method leads to priceless assets for these looking for step-by-step steerage from a coding teacher. What a superb solution to share coding options! Fantastic work, Austin!
My coding options ⬇
Day 4: AI Christmas E-card Generator
Task:
-
Use AI to generate a Christmas joke.
-
Display the joke within the DOM.
This code makes use of the Hugging Face Inference API to generate a Christmas joke and show it within the doc.
The HfInference class from the @huggingface/inference package deal is imported originally. An occasion of HfInference is created with the API key saved within the atmosphere variable course of.env.HUGGING_FACE_API_KEY.
A reference to the HTML factor with the category identify ‘joke-display’ is saved within the displayEl variable.
An occasion listener is added to the HTML factor with the id ‘window-container’. When this factor is clicked, the next actions are carried out:
-
The textual content content material of the ‘joke-display’ factor is about to ‘Loading…’.
-
The kinds of the ‘left-door’ and ‘right-door’ parts are up to date to set off CSS animations that open the doorways.
-
The type of the ‘joke-display’ factor is up to date to set off a CSS animation that shows the joke.
-
The
textGenerationtechnique of theHfInferenceoccasion known as. This technique generates a textual content primarily based on the supplied mannequin and inputs. The inputs are set to a string that prompts the mannequin to generate a Christmas joke. Thetemperaturepossibility is about to0.7, which controls the randomness of the output. A decrease temperature leads to extra centered and constant output, whereas the next temperature leads to extra various and shocking output. -
The
use_cachepossibility is about tofalseto make sure that the generated textual content will not be cached and is completely different every time the operate known as. -
The generated textual content is about because the textual content content material of the ‘joke-display’ factor.
This script gives a enjoyable and interactive solution to generate Christmas jokes utilizing AI. (However, I do not fairly get the joke! "The Christmas tree is an excellent tree*" 😂)*
import { HfInference } from '@huggingface/inference';
const hf = new HfInference(course of.env.HUGGING_FACE_API_KEY);
const displayEl = doc.querySelector('.joke-display');
doc.getElementById('window-container').addEventListener('click on', async operate () {
displayEl.innerText = 'Loading...';
doc.querySelector('.left-door').type = "animation: left-open 0.3s forwards";
doc.querySelector('.right-door').type = "animation: right-open 0.3s forwards";
doc.querySelector('.joke-display').type = "animation: display-joke 0.3s forwards";
const response = await hf.textGeneration({
mannequin: 'google/flan-t5-xxl',
inputs: `Q: Give me a Christmas joke.`,
temperature: 0.7,
}, {
use_cache: false
});
displayEl.innerText = response.generated_text;
});
Day 5: Jeopardy Card Flip
Task:
-
The card has two sides and flips entrance to again on hover
-
Match kinds as intently as potential
-
CSS solely
This CSS code is used to create a flipping card impact on a webpage. It makes use of a number of CSS properties to realize this impact.
The physique and html kinds are used to heart the cardboard on the web page, set the background coloration, and specify the font coloration and sort.
The :root selector is used to outline CSS variables which can be utilized all through the doc. In this case, it units the colours for the cardboard and font.
The .card class units the dimensions and place of the cardboard. The perspective property provides the cardboard a 3D impact when it flips.
The .card-front and .card-back courses are used to type the back and front of the cardboard. The backface-visibility property hides the again of the cardboard when it is not flipped. The transform-style property is used to protect the 3D place of the cardboard when it flips. The transition property creates the flipping animation.
The remodel property in .card-back class initially rotates the again of the cardboard by 180 levels, hiding it from view.
When the cardboard is hovered over, the .card:hover .card-front and .card:hover .card-back kinds rotate the cardboard to indicate the again of the cardboard and conceal the entrance, creating the flipping card impact.
physique, html {
margin: 0;
padding: 0;
show: flex;
justify-content: heart;
align-items: heart;
peak: 100vh;
background-color: var(--jeopardy-blue);
coloration: var(--font-color-main);
font-family: Arial, sans-serif;
}
:root {
--jeopardy-blue: #060CE9;
--font-color-main: #fff;
}
.card {
place: relative;
width: 300px;
peak: 200px;
perspective: 1000px;
}
.card-front, .card-back {
place: absolute;
width: 100%;
peak: 100%;
backface-visibility: hidden;
show: flex;
justify-content: heart;
align-items: heart;
padding: 20px;
box-sizing: border-box;
border: 1px stable var(--font-color-main);
border-radius: 10px;
transition: remodel 0.8s;
transform-style: preserve-3d;
}
.card-front {
background-color: var(--jeopardy-blue);
}
.card-back {
background-color: var(--font-color-main);
coloration: var(--jeopardy-blue);
remodel: rotateY(180deg);
}
.card:hover .card-front {
remodel: rotateY(180deg);
}
.card:hover .card-back {
remodel: rotateY(360deg);
}
Day 6: Secret Santa
Task:
Write a operate to randomly assign every particular person in an array a "Secret Santa," who’s another person within the array. No one ought to be assigned to themselves as their very own Secret Santa.
{Bob: "Carly", Carly: "Alice", Alice: "Dan", Dan: "Ed", Ed: "Ferdinand", Ferdinand: "Ginny", Ginny: "Bob"}
This operate, generateSecretSantaPairs, is designed to arrange a Secret Santa present change. It accepts an array of individuals’s names.
-
First, it shuffles the array of names. This is completed by swapping every identify with one other randomly chosen identify from the array. This ensures that the project of Secret Santas is random.
-
Then, it creates an empty object,
pairs, the place we are going to retailer the ultimate pairs of individuals and their Secret Santas. -
Next, it loops via the shuffled array of names. For every identify, it assigns the following identify within the array as their Secret Santa and shops this pair within the
pairsobject. For instance, the primary particular person will get the second particular person as their Secret Santa, the second particular person will get the third, and so forth. -
When it reaches the final particular person within the array, it assigns them the primary particular person as their Secret Santa. This is what we name "round project".
-
Finally, it outputs the
pairsobject which incorporates the pairs of individuals and their Secret Santas.
This operate ensures that everybody will get a singular Secret Santa and nobody is left and not using a present. It’s a enjoyable and honest solution to arrange a Secret Santa present change!
const folks = ["Alice", "Bob", "Carly", "Dan", "Ed", "Ferdinand", "Ginny"]
operate generateSecretSantaPairs(arr) {
// Shuffle array
for (let i = arr.size - 1; i > 0; i--) {
let j = Math.flooring(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}
let pairs = {};
// Circular project
for(let i = 0; i < arr.size; i++) {
if(i === arr.size - 1) {
pairs[arr[i]] = arr[0];
} else {
pairs[arr[i]] = arr[i + 1];
}
}
console.log(pairs);
return pairs;
}
generateSecretSantaPairs(folks)
Day 7: Christmas Present Wishlist
Task:
-
Iterate over the wishlist array.
-
Dynamically render your wishlist from the array.
-
Style the wishlist with CSS.
This JavaScript code is used to dynamically generate a wishlist on a webpage. It consists of an array of wishlist gadgets and a JavaScript operate that creates and appends this stuff to the webpage.
The wishlist array incorporates 5 gadgets that you simply want for. These gadgets are strings and characterize the names of the items you need.
The wishlistItems fixed is a set of all HTML parts with the category identify "wishlist".
The wishlist.forEach loop goes via every merchandise within the wishlist array. For every merchandise, it does the next:
-
Creates a brand new
lifactor utilizingdoc.createElement("li"). -
Sets the textual content content material of this
lifactor to the present merchandise within the array. -
Adds the category "wishlist-item" to the
lifactor. -
Appends this
lifactor to the primary factor within thewishlistItemsassortment.
By the top of the loop, every merchandise within the wishlist array is remodeled into an li factor and added to the webpage.
const wishlist = [
"ATARI 2600+ Console",
"Stack of Atari 2600 games",
"Classic Atari T-Shirt",
"Walkman with Retro Mixtapes",
"Board Game Twilight Imperium",
];
const wishlistItems = doc.getElementsByClassName("wishlist");
wishlist.forEach((merchandise)=>{
const recordItem = doc.createElement("li");
recordItem.textContent = merchandise;
recordItem.classList = "wishlist-item";
wishlistItems[0].appendChild(recordItem);
})
The following CSS code block kinds a webpage with a wishlist.
The physique selector kinds your complete webpage. It units the physique to fill your complete peak of the viewport (100vh). The show: flex, justify-content: heart, and align-items: heart properties heart the content material each vertically and horizontally. The background property units a background picture that covers your complete physique.
The .wishlist selector kinds a block factor. It units the width to 300px, provides a dotted border, and a field shadow for a 3D impact.
The .wishlist-item selector kinds every merchandise within the wishlist. It units the colour to white, facilities the textual content, and makes the textual content daring. It additionally makes use of flexbox to heart the content material inside every record merchandise.
The .wishlist-item:nth-child(odd) and .wishlist-item:nth-child(even) selectors add a purple and inexperienced background coloration to odd and even-numbered record gadgets, respectively.
physique {
margin: 0;
padding: 0;
peak: 100vh;
show: flex;
flex-direction: column;
justify-content: heart;
align-items: heart;
font-family: 'Mountains of Christmas', serif;
font-size: 20px;
text-shadow: 2px 2px 2px purple, -2px -2px 1px black;
coloration: blanchedalmond;
background: url("https://cdn.pixabay.com/photograph/2021/11/09/15/32/christmas-6781762_1280.jpg") no-repeat heart heart;
background-size: cowl;
}
.wishlist {
width: 300px;
border: 10px dotted blanchedalmond;
box-shadow: 5px 5px 5px rgba(0,0,0,0.2);
}
.wishlist-item {
coloration: white;
text-align: heart;
text-shadow: 1px 1px 1px black;
font-weight: bolder;
font-size: 22px;
list-style-type: sq.;
peak: 50px;
show: flex;
justify-content: heart;
align-items: heart;
}
.wishlist-item:nth-child(odd) {
background-color: purple
}
.wishlist-item:nth-child(even) {
background-color: inexperienced;
}
Day 8: Animated Progress Bar
Task:
-
Build a CSS animation of a progress bar filling to 100%. The animation ought to run constantly, with a small pause when the bar is stuffed 100%.
-
The progress begins purple, turns blue, at 50%, and inexperienced when full.
-
CSS solely!
This code creates an animated progress bar that adjustments coloration from purple to blue to inexperienced because it fills up with a sweet cane background!
The :root part defines coloration variables for the progress bar. The physique part kinds the webpage, together with setting a Christmas-themed background picture and aligning content material within the heart.
The h1 part kinds the title with a big font measurement, white coloration, and a shadow impact. The .container part kinds the container of the progress bar.
The .progress-bar part kinds the progress bar itself, giving it a width, peak, and a striped background. The .progress-status part is the place the animation is utilized to create a filling impact.
The @keyframes progress part defines the animation, dictating that the progress bar ought to begin at a width of 0% (empty), then enhance to a width of fifty% (half full), and eventually attain a width of 100% (totally stuffed). The bar’s coloration adjustments at every stage, going from purple to blue to inexperienced.
:root {
--progressbar-bg: lightgrey;
--start: purple;
--middle: blue;
--finish: inexperienced;
}
physique {
margin: 0;
padding: 0;
show: flex;
flex-direction: column;
justify-content: heart;
align-items: heart;
peak: 100vh;
background-image: url("https://cdn.pixabay.com/photograph/2018/12/19/22/00/christmas-3884891_1280.jpg");
background-size: cowl;
background-position: heart;
font-family: 'Mountains of Christmas';
}
h1 {
font-size: 50px;
coloration: white;
text-shadow: 2px 2px 2px black, -2px -2px 2px purple;
}
.container {
border: 5px stable black;
border-radius: 25px;
box-shadow: 3px 3px 3px rgba(0,0,0,0.5);
width: 300px;
margin: 50px auto;
}
.progress-bar {
width: 100%;
peak: 30px;
background: repeating-linear-gradient(
45deg,
white,
white 10px,
purple 10px,
purple 20px
);
border-radius: 15px;
overflow: hidden;
}
.progress-status {
peak: 100%;
width: 0;
background: var(--start);
animation: progress 3s infinite;
}
@keyframes progress {
0% {
width: 0;
background: var(--start);
}
50% {
width: 50%;
background: var(--middle);
}
100% {
width: 100%;
background: var(--finish);
}
}
Day 9: AI Christmas E-card Generator
Task:
-
Use AI to generate a picture for a Christmas e-card
-
Render the picture to the DOM
I assumed it might be entertaining to switch the supplied code, reworking it right into a Star Wars-themed card! I used the Hugging Face API, and I utilized Scrimba’s technique of storing atmosphere variables.
My immediate:
"Create a festive picture that captures the spirit of the Star Wars universe’s "Hope Day". The scene ought to be set on the plush, forested residence planet of Chewbacca, Kashyyyk. Specifically, it ought to depict Chewbacca and his household, together with his spouse Malla, his son Lumpy, and his father Itchy, celebrating Hope Day collectively. They ought to be on a balcony of their towering treehouse, as seen within the Star Wars Christmas Special and the film Revenge of the Sith. The household ought to be joyously engaged in typical vacation actions, resembling exchanging items or sharing a meal. The background ought to function the dense, towering Wroshyr bushes of Kashyyyk, bathed within the heat, golden mild of sundown. To add a festive contact, the treehouse and surrounding bushes may very well be embellished with glowing lanterns or strands of lights. The card ought to embody the heat, pleasure, and hope that characterizes each the vacation season and the spirit of Star Wars’ "Hope Day"."
This script makes use of the Hugging Face Inference API to generate a picture primarily based on consumer enter.
First, it imports the HfInference class from the @huggingface/inference package deal. This class gives strategies to work together with the Hugging Face Inference API.
Then, it will get references to a number of HTML parts: a dialog modal, a picture container, an enter kind, and a consumer enter subject.
The generateImage operate is an asynchronous operate that creates an occasion of HfInference with a supplied API key. It then calls the textual contentToPicture technique on this occasion, passing in an object that specifies the mannequin to make use of, the inputs to offer to the mannequin, and any further parameters. This technique returns a Blob representing the generated picture. The operate then converts this Blob to an information URL and returns it.
blobToDataURL is a helper operate that converts a Blob to an information URL. It creates a brand new FileReader, units up occasion listeners to resolve or reject the Promise when the learn operation is full, and begins studying the Blob as an information URL.
The occasion listener for the ‘submit’ occasion on the enter kind prevents the default kind submission conduct, closes the dialog modal, and units the inside HTML of the picture container to a loading spinner. It then calls generateImage, waits for it to finish, and units the src attribute of an img factor within the picture container to the returned knowledge URL. Finally, it clears the consumer enter subject.
The present technique known as on the dialog modal to show it when the script runs.
import { HfInference } from '@huggingface/inference'
const dialogModal = doc.getElementById('dialog-modal')
const imageContainer = doc.getElementById('image-container')
const enterForm = doc.getElementById('input-form');
const consumerInput = doc.getElementById('user-input');
async operate generateImage() {
const inference = new HfInference(course of.env.HUGGING_FACE_API_KEY);
const blob = await inference.textual contentToPicture({
mannequin: "stabilityai/stable-diffusion-2",
inputs: consumerInput.worth,
parameters: {
negative_prompt: "blurry",
}
});
return await blobToDataURL(blob);
}
operate blobToDataURL(blob) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.consequence);
reader.onerror = reject;
reader.readAsDataURL(blob);
});
}
enterForm.addEventListener('submit', async (e) => {
e.preventDefault();
dialogModal.shut();
imageContainer.innerHTML = '<div class="spinner"></div>';
imageContainer.innerHTML = `<img src="${await generateImage()}" alt="${consumerInput.worth}">`;
consumerInput.worth = '';
});
dialogModal.present();
Day 10: Rockin’ Around
Task:
Add code inside the playSong(id) operate to make the YouTube Player play the YouTube tune.
I’d prefer to take a second to elucidate why it is helpful for builders to create a weblog. This solved this actual JavaScriptmas problem final yr, and to unravel it this yr, I learn the answer I wrote in my JavaScriptmas 2022 article!
In this problem, the entire heavy lifting is already accomplished. All that is wanted to unravel it’s to write down a playSong operate that returns the YouTube ID for the chosen tune. This is completed by utilizing string concatenation which updates the worth of the participant.src.
Initially, the participant’s supply is about to "https://www.youtube.com/embed/PoAjmmD89Vw?autoplay=1", which performs the model of White Christmas as seen within the vacation basic, Home Alone. The YouTube ID for this tune is PoAjmmD89Vw, which is a part of the supplied URL.
So, the problem is solved by updating the participant.src worth utilizing the passed-in ID worth of the tune that’s chosen by the consumer once they click on on the corresponding buttons.
const participant = doc.getElementById("participant")
operate playSong(id) {
// Challenge: Add code right here to make the youtube participant play the brand new YouTube tune
participant.src = `https://www.youtube.com/embed/${id}?autoplay=1`
console.log(participant.src);
}
If you wish to be taught extra about my journey with Scrimba and the way studying with them might show you how to, you’ll be able to learn my article: How Scrimba helps me and plenty of others to turn into assured, well-prepared internet builders
Scrimba has as soon as once more impressed and impressed me! You can learn my full Scrimba evaluation on my 12/13/2020 publish.
"That’s among the best Scrimba evaluations I’ve ever learn, @MikeJudeLarocca. Thank you! 🙏 "
— Per Harald Borgen, CEO of Scrimba December 14, 2020
10% Scrimba Discount!
If you are excited by taking a paid course from Scrimba, you’ll want to use the low cost code supplied: https://scrimba.com/pricing?coupon=Michael-Larocca-Discount-2023#be part of
Valid for an extra 10% off semester and annual plans. Expires on July thirty first, 2024
Conclusion
Scrimba’s annual JavaScriptmas occasion is a enjoyable, festive solution to decide to coding every day. Whether you’re a new coder or a seasoned one, you’ve gotten a possibility to share your work with the neighborhood, make new mates, and even get an opportunity to win prizes!
If you are excited by persevering with studying with Scrimba after the FREE occasion, you’ll want to try their many FREE programs! If you might be able to decide to changing into a hireable front-end internet developer, be looking out for discounted course charges!
Don’t miss out on this thrilling coding occasion! Participate in Scrimba’s JavaScriptmas at this time, share your options, join with fellow builders, and enhance your abilities whereas having enjoyable! Merry JavaScriptmas! 🎄
Let’s join! I’m lively on LinkedIn and Twitter.
Are you now excited by collaborating on this yr’s Scrimba’s JavaScriptmas? Have you already participated in final yr’s Scrimba’s JavaScriptmas? Please share the article and remark!
Vinyl
through DEV Community: javascript https://ift.tt/0L34FUy
December 11, 2023 at 11:26PM
-
Product on sale
Audiophile Vinyl Records Cleaning BundleOriginal price was: €83.88.€73.88Current price is: €73.88. incl. VAT -
Product on sale
Easy Start Vinyl Records Cleaning KitOriginal price was: €83.88.€73.88Current price is: €73.88. incl. VAT -
Vinyl Records Cleaner Easy Groove Concentrate€41.94 incl. VAT -
Easy Groove Super Set€238.80 incl. VAT -
Easy Groove Enzycaster – vinyl records prewash cleaner€41.94 incl. VAT -
Easy Groove Extreme MK. II- vinyl records prewash cleaner€54.00 incl. VAT -
Vinyl Records Cleaner – Easy Groove Virgin Concentrate€42.00 incl. VAT -
Easy Groove Spray&Wipe vinyl records cleaner€41.94 incl. VAT


















