Fundamentals (Paid)
  • 🚀Course Overview
  • Course Logistics
    • 🏫Course Methodology
      • 🧩Course Components
      • 💬Community Channels
      • 🎲Course Projects
    • 💻Required Hardware and Software
      • ☝️Required Software 1
      • ✌️Required Software 2
      • 👍Recommended Setup
    • 🗓️Schedule
    • 💡Tips and Tricks
      • 📒Coding Strategies
      • 🛠️Tooling Pro Tips
    • 🎓Post-Course
      • 🎓LinkedIn Certificates
      • 🚂Bootcamp Admission Criteria
  • 1: Introduction
    • 1.1: What is Coding?
    • 1.2: Web Browsers
    • 1.3: Command Line
    • Additional Resources 1
  • 2: Basic Data Manipulation
    • 2: Operators and Expressions
      • 2.1: Arithmetic Operators | Mathematical Expressions
      • 2.2: Assignment Operators | Variables
    • 2.3: Our First Program
    • Additional Resources 2
  • 3: Structuring and Debugging Code
    • 3.1: Functions
    • 3.2: Errors
    • Additional Resources 3
  • 4: Conditional Logic
    • 4.1: Intro to Logic
    • 4.2: Pseudo-Code, Boolean Or
    • 4.3: Boolean AND, NOT
    • 4.4: Input Validation
    • Additional Resources 4
  • 5: Managing State and Input Validation
    • 5.1: Program Lifecycle and State
    • 5.2: Program State for Game Modes
    • Additional Resources 5
  • 6: Arrays and Iteration
    • 6.1: Arrays
    • 6.2: Loops
    • 6.3: Loops with Arrays
    • Additional Resources 6
  • 7: Version Control
    • 7.1: Git
    • Additional Resources 7
  • 8: GitHub
    • 8.1: Intro to GitHub
    • 8.2: GitHub Fork and Clone
    • 8.3: GitHub Pull Request
    • 8.4: GitHub Repo Browsing
    • 8.5: Deployment
    • Additional Resources 8
  • 9: JavaScript Objects
    • 9.1: JavaScript Objects
    • 9.2: Card Deck Generation with Loops
  • 10: Advanced
    • 10.1 HTML
    • 10.2: CSS
    • 10.3: The Document Object Model
    • 10.4: DOM Manipulation
    • 10.5: Advanced Debugging with Sources Tab
  • 11: POST COURSE EXERCISES
    • DOM
    • Further Readings
  • In-Class Exercises
    • Day 2: Basic File and Data Manipulation
    • Day 3: Functions
    • Day 4: If Statements, Boolean Or, Boolean And
    • Day 5: Program State
    • Day 6: Scissors Paper Stone Redux
    • Day 7: Loops
    • Day 8: Arrays and Loops
    • Day 9: Beat That Redux
    • Day 10: Moar Cards / Chat Bot
    • Day 11: Blackjack Redux, DOM
  • Projects
    • Project 1: Scissors Paper Stone
      • Project 1: Scissors Paper Stone (Part 1)
      • Project 1: Scissors Paper Stone (Part 2)
    • Project 2: Beat That!
    • Project 3: Blackjack
  • Past Projects
    • Drawing With Emojis
    • Guess the Word
Powered by GitBook
On this page
  • Introduction
  • Reference Solution
  1. In-Class Exercises

Day 7: Loops

PreviousDay 6: Scissors Paper Stone ReduxNextDay 8: Arrays and Loops

Last updated 2 years ago

Introduction

Today we will practice arrays and loops. For each exercise except Infinite Loop, make a copy of the .

Pick either one of the Emoji Drawing or Multi-Dice Game exercise and work through from Base to your preferred level of comfort, before attempting the other exercise.

Base

Use loops to create an app that draws emojis into the grey box. See for how to input Emoji on Windows and for how to input emoji on Mac.

See an example of all problems .

Number of Characters

The user will enter a number of characters to display on the screen.

For example, if the user enters 4 they will see this:

Square

The user will enter the dimensions of a square to display on the screen.

Use a loop within a loop and the <br> HTML tag in your output to create the square.

For example, if the user enters 4 they will see this:

Comfortable

Triangle

The user will enter the dimensions of a triangle to display on the screen.‌

Use a loop within a loop, a conditional and the <br> HTML tag in your output to create the triangle.

For example, if the user enters 4 they will see this:

More Comfortable

Outline Square

The user will enter the dimensions of a square to display on the screen. The square is outlined by a different character.

For example, if the user enters 4 they will see this:

Center Square

The user will enter the dimensions of a square to display on the screen. The square is outlined by a different character and there is another different character in the center. The app doesn't allow dimensions that will not allow the center character.

For example, if the user enters 5 they will see this:

Base

  1. Create a dice-guessing game with a variable number of dice rolls determined by the user.

  2. The game will have 2 modes.

  3. In the 1st mode, the user will enter the number of dice they wish to roll.

  4. In the 2nd mode, the user will enter a guess that will apply to all dice rolls. For example, if the user has chosen to roll 2 dice in Mode 1 and guesses 4 in Mode 2, that guess of 4 will apply to both Dice 1 and Dice 2.

  5. After the user guesses, the program will run a loop where the number of iterations is the number of dice rolls from Mode 1. Each loop iteration will roll a dice and verify if the user has won.

  6. If the user guesses correctly for any of the dice rolls, the user wins.

  7. The game keeps track of and outputs the overall win-loss record.

More Comfortable

Multi-Round Multi-Dice Game

  1. Alter the previous multi-dice game such that the user plays 4 rounds in the 2nd mode.

  2. After the user enters their guess in Mode 2, the program enters a loop that runs 4 rounds.

  3. Within each round the game will roll the number of dice the user specified and compare them with the single user guess.

  4. If the user guessed correctly for any dice rolls in a round, they win that round.

  5. The game will continue to output overall win-loss record, where each of the 4 rounds count as wins or losses.

Two Player Multi-Round Multi-Dice Game

  1. Change the game to support 2 players, starting with Player 1.

  2. The gameplay follows the multi-round multi-dice game above. After each player's turn, that player will have won between 0 and 4 rounds, because each player plays 4 rounds per turn.

  3. The game alternates between players indefinitely and outputs win-loss record for each player.

Multi-Player Multi-Round Multi-Dice Game

Change the game to ask how many players are playing the game. Players will take turns playing the game as above.

Reference Solution

More dice rolling and guessing! See an example of all problems .

is a reference solution to the Drawing exercises, and is a reference solution for Dice Game exercises. Please only view the reference solution for each exercise after you have attempted the exercise yourself. Note that there are many ways to implement these solutions and the reference solution is only 1 way.

here
Here
here
starter code
here
here
here