Giter VIP home page Giter VIP logo

hw-loops-conditionals's Introduction

ga

HW: Arrays, Loops, and Conditional Reps


Type: Deliverable
Competencies: Arrays, Loops, Conditionals
Language: JavaScript


Setup

  1. Fork this repo to your account and then clone it down to your compumter into your sei/deliverables directory.

  2. Inside the directory created by the clone, build our file structure (index.html and app.js). Put your answers in app.js.

  3. Keep your answers organized! Include a commented header for each section in your answers file.

  4. If you're stuck on something for "too long" or get overly frustrated, make a comment and move on. Return to it later.

  5. After each section (even if you're not fully done with it), add and commit your work. Use the commit messages that you see at the end of each section. If you go back and fix a section, commit again with an updated message.

  6. When you are done with your homework, push up to the forked repo on your personal account with git push origin main. Create a pull request from your fork to WC-SEIR-7-06/HW-Loops-Conditionals.

  • Remember: the "Bonus" questions and the "Hungry for More" questions don't count against you, they're just extra questions if you wanna push beyond the baseline.

Easy Going

  1. Write a for loop that will log the numbers 1 through 20.

๐Ÿ”ด The commit message should read:
"Commit 1 - Easy Going answered"

Get Even

  1. Write a for loop that will log only the even numbers in 0 through 200.

Hint: Think about the increment expression.


๐Ÿ”ด The commit message should read:
"Commit 2 - Get Even answered"

Excited Kitten

  1. Write code that logs "Love me, pet me! HSSSSSS!" 20 times.

  2. For every even number in your loop, log "...human...why you taking pictures of me?...", "...the catnip made me do it...", or "...why does the red dot always get away..." at random.

Hint: You will need to use Math.random()


๐Ÿ”ด The commit message should read:
"Commit 3 - Excited Kittens answered"

Working with Arrays

Use the following arrays to answer the questions below (name, age, hometown):

const kenny = ["Kenny", 1000, "Austin"];
const jimHaff = ["Jim H", 16, "All cities"];
const reuben = ["Reuben", 22, "Durham"];
const jimClark = ["Jim C", 186, "LA"];
const ryan = ["Ryan", 65, "Denver"];
  1. Jim Clark decides that Kenny can't be named "Kenny" anymore. Remove "Kenny" from the kenny array and replace it with "Gameboy".

  2. Jim Clark just had his birthday; change jimClark's array to reflect him being a year older. Don't just hard code 187--pretend that you didn't already know that his age is 186, and write your code to just make him a year older than whatever age he was.

  3. Ryan is Batman maybe. Or possibly Robin. Change Ryan's hometown from "Denver" to "Gotham City".

  4. Reuben left Durham 5 years ago to come to Chicago. First, remove "Durham" from Reuben's array, and then add "Chicago". (Note: remove and then add is different from simply changing the value at that index.)

  5. Jim Haff could be literally anywhere in the world. Remove "All cities" from his array, then pick any 3 cities you like, and add them to Jim's array. If you did it in 3 lines of code that's fine, but see if you can do it in one line of code

  6. Bonus: Whoops! Jim Haff is actually only allowed to be in one of two cities. Whatever the first of the 3 cities for Jim Haff is now, remove it from the array using .splice()


๐Ÿ”ด The commit message should read:
"Commit 5 - Getting to Know You answered"

Yell at the Ninja Turtles

  1. Create an array with the members of the ninja turtles (Donatello, Leonardo, Raphael, Michaelangelo)

  2. Use a for loop to call .toUpperCase() on each of them and print out the result.

  3. Bonus: Modify the answer you just wrote. Instead of all letters being uppercase, make the letters alternate back and forth between uppercase and lowercase.


๐Ÿ”ด The commit message should read:
"Commit 6 - Yell at the Ninja Turtles answered"

Return of the Closets

Below, we've given you examples of Kristyn and Thom's closets modeled as data in JavaScript. Use this data to answer the following questions.

const kristynsCloset = [
  "left shoe",
  "cowboy boots",
  "right sock",
  "GA hoodie",
  "green pants",
  "yellow knit hat",
  "marshmallow peeps"
];

// Thom's closet is more complicated. Check out this nested data structure!!
const thomsCloset = [
  [
    // These are Thom's shirts
    "grey button-up",
    "dark grey button-up",
    "light blue button-up",
    "blue button-up",
  ],[
    // These are Thom's pants
    "grey jeans",
    "jeans",
    "PJs"
  ],[
    // Thom's accessories
    "wool mittens",
    "wool scarf",
    "raybans"
  ]
];

Alien Attire

  1. Kristyn's left shoe has traveled through time and space and turned up in Thom's accessories drawer! Remove Kristyn's shoe from the array and save it to the variable kristynsShoe. Use that variable to add Kristyn's lost shoe to Thom's accessories array.

  2. Modify your code to put together 3 separate outfits for Kristyn and Thom. Put the output in a sentence to tell us what we'll be wearing. Mix and match!


๐Ÿ”ด The commit message should read:
"Commit 7 - Kristyn and Thom have their outfits ready for class - array practice"

Dirty Laundry

Continue looking at the closet arrays:

  1. Time to do laundry - loop through Kristyn's closet and log the sentence "WHIRR: Now washing (item)" for each item in the array.

  2. Thom wants to do inventory on his closet. Using bracket notation, log the arrays (not the elements in the arrays) containing all of Thom's shirts, pants, and accessories.


๐Ÿ”ด The commit message should read:
"Commit 8 - Looping through closets".

Hungry for more?

The rest of these problems are for extra practice and not required to complete.

Fizz Buzz

NOTE: THIS IS A CLASSIC RITE-OF-PASSAGE FOR JAVASCRIPT PROGRAMMERS, ESPECIALLY ONES AT GA

Write a javascript application that logs all numbers from 1 - 100 AND:

  1. If a number is divisible by 3 log "Fizz" instead of the number.

  2. If a number is divisible by 5 log "Buzz" instead of the number.

  3. If a number is divisible by 3 and 5 log "FizzBuzz" instead of the number, "Fizz", or "Buzz".


๐Ÿ”ด The commit message should read:
"Commit 4 - Fizz Buzz answered"

Multiples of 3 and 5

Yes, you might have tackled this earlier, but try it again (don't look back at your other code ๐Ÿ‘€)

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

๐Ÿ‘ You just solved Project Euler problem 1! ๐Ÿ‘

Tip: Get used to thinking about how to solve problems now. Will help immensely with coding challenges, and get your coding brain muscles nice and flexed for the class. Make a habit of going to Project Euler and taking a crack at the problems


๐Ÿ”ด The commit message should read:
"Commit 9 - Project Euler Problem 1 answered"

Triangles

  1. declare a variable argument and set it equal to 7.

  2. Write a loop that console logs a "left isosceles" triangle (SEE BELOW) made of '#' that has the height and length of argument.

Ex: argument is 7

#
##
###
####
#####
######
#######
  1. Write a loop that console logs a "right isosceles" triangle (SEE BELOW) made of '#' that has the height and length of argument. This is deceptively tricky.

Ex: argument is 7

      #
     ##
    ###
   ####
  #####
 ######
#######
  1. Write a loop that console logs an "upside down left" isosceles triangle made of '#' that has the height and length of the argument.

Ex: argument is 7

#######
######
#####
####
###
##
#
  1. Write a loop that console logs an "upside down right" isosceles triangle made of '#' that has the height and length of the argument. This is also tricky.

Ex: argument is 7

#######
 ######
  #####
   ####
    ###
     ##
      #
  1. Change the value of argument and reload your code and marvel at how you just solved a challenging problem and feel proud of yourself.

๐Ÿ”ด The commit message should read:
"Commit 10 - Triangles answered"

Find the Median

  • Find the median number in the following nums array, then console.log that number.
  • hint this will likely involve breaking down the problem into a few steps
  • hint: Click "Details" below (don't read this unless you've been stuck for a while)
if you check the length of the array / 2, you might get not get a whole number. In which case, look into `Math.floor( // something )`
const nums = [14, 11, 16, 15, 13, 16, 15, 17, 19, 11, 12, 14, 19, 11, 15, 17, 11, 18,12, 17, 12, 71, 18, 15, 12];

Expected output:
=> 15

๐Ÿ”ด The commit message should read:
"Commit 11 - Find the Median answered"

hw-loops-conditionals's People

Contributors

nicholasgacicia avatar meganroberta80 avatar reuben-ga avatar jimbojones1 avatar michaelpetty avatar msolorio avatar h64 avatar reubenayres avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.