Self-paced

Explore our extensive collection of courses designed to help you master various subjects and skills. Whether you're a beginner or an advanced learner, there's something here for everyone.

Bootcamp

Learn live

Join us for our free workshops, webinars, and other events to learn more about our programs and get started on your journey to becoming a developer.

Upcoming live events

Learning library

For all the self-taught geeks out there, here is our content library with most of the learning materials we have produced throughout the years.

It makes sense to start learning by reading and watching videos about fundamentals and how things work.

Search from all Lessons


LoginGet Started

Register to 4Geeks

← Back to Projects

Random Card Generator

Difficulty

  • easy

Average duration

4 hrs

Technologies

Difficulty

  • easy

Average duration

4 hrs

Random Card Dealer in JavaScript, HTML and CSS

Random Card Dealer in JavaScript, HTML and CSS

In this project, you will learn how to change your website styles during the runtime using VanillaJS (plain normal js).

📝 Instructions

Create an algorithm that randomly builds a card on every refresh:

  1. Every time the website refreshes, a new random card needs to show.

  2. The card must have one of the possible suits: Hearts, Spades, Clubs, or Diamonds.

  3. The card value must be one of the following: 2 to 10, King, Queen, Jack or Ace (no joker).

In the end, the project needs to look similar to this demo.

🌱 How to start this project

Do not clone this repository because we are going to be using a different template.

We recommend opening the vanilla.js boilerplate using a provisioning tool like Codespaces (recommended) or Gitpod. Alternatively, you can clone it on your local computer using the git clone command.

This is the repository you need to open or clone:

1https://github.com/4GeeksAcademy/vanillajs-hello

👉 Please follow these steps on how to start a coding project.

💡 Important: Remember to save and upload your code to GitHub by creating a new repository, updating the remote (git remote set-url origin <your new url>), and uploading the code to your new repository using the add, commit and push commands from the git terminal.

💡 Hints

  • Remember that the first event of a website lifecycle is onLoad (your code starts running there). You should generate a random number between 1 and 4 to pick a suit and another random number between 0 and 12 to pick a card number.

  • Create a general .card class that applies the common styles to each card, and one additional CSS class for each suit: .spade, .club, .heart & .diamond.

  • Apply the .card class to the entire div, but only apply one of the suit classes at a time, depending on what suit you want to apply. For example, a 3 of hearts will have this HTML declaration:

1<div class='card heart'></div>
  • You can grab the icons from here (copy and paste into your code): ♦ ♥ ♠ ♣

😎 Feeling Confident?

The following requirements are not needed to successfully finish this project, but you can try and challenge yourself!

+1 Add a button that generates a new card when clicked.

+1 Add a timer that generates a new card every 10 seconds.

+1 Allow the user to specify the card width and height using text inputs.

This and many other projects are built by students as part of the 4Geeks Academy Coding Bootcamp by Alejandro Sanchez and many other contributors. Find out more about our Full Stack Developer Course, and Data Science Bootcamp.

Sign up and get access to solution files and videos

We will use it to give you access to your account.
Already have an account? Login here.

By signing up, you agree to the Terms and conditions and Privacy policy.

Difficulty

  • easy

Average duration

4 hrs

Difficulty

  • easy

Average duration

4 hrs

Difficulty

  • easy

Average duration

4 hrs

Difficulty

  • easy

Average duration

4 hrs

Sign up and get access to solution files and videos

We will use it to give you access to your account.
Already have an account? Login here.

By signing up, you agree to the Terms and conditions and Privacy policy.

Difficulty

  • easy

Average duration

4 hrs

Difficulty

  • easy

Average duration

4 hrs

Supplementary Material

In order to prepare better for completing this exercises, we suggest the following materials

Lesson

What is DOM: Document Object Model

Lesson

What is JavaScript? Learn to Code in JavaScript

Exercise

Javascript Beginner Tutorial (interactive)

Exercise

Learn how to manipulate The DOM with JS