Giter Club home page Giter Club logo

js_exercises's Introduction

js_exercises

Practice with variable, if/else statements, for loops, and arrays

Variables

The Age Calculator

Forgot how old someone is? Calculate it!

  • Store the current year in a variable.
  • Store their birth year in a variable.
  • Calculate their 2 possible ages based on the stored values.
  • Output them to the screen like so: "They are either NN or NN", substituting the values.

The Lifetime Supply Calculator

Ever wonder how much a "lifetime supply" of your favorite snack is? Wonder no more!

  • Store your current age into a variable.
  • Store a maximum age into a variable.
  • Store an estimated amount per day (as a number).
  • Calculate how many you would eat total for the rest of your life.
  • Output the result to the screen like so: "You will need NN to last you until the ripe old age of X".

The Geometrizer

Calculate properties of a circle, using the definitions here.

  • Store a radius into a variable.
  • Calculate the circumference based on the radius, and output "The circumference is NN".
  • Calculate the area based on the radius, and output "The area is NN".

The Temperature Converter

It's hot out! Let's make a converter based on the steps here.

  • Store a celsius temperature into a variable.
  • Convert it to fahrenheit and output "NN°C is NN°F".
  • Now store a fahrenheit temperature into a variable.
  • Convert it to celsius and output "NN°F is NN°C."

If/else

What number's bigger?

  • Write a function named greaterNum that:
    • takes 2 arguments, both numbers.
    • returns whichever number is the greater (higher) number.
  • Call that function 2 times with different number pairs, and log the output to make sure it works (e.g. "The greater number of 5 and 10 is 10.").

The Grade Assigner

  • Write a function named assignGrade that:
    • takes 1 argument, a number score.
    • returns a grade for the score, either "A", "B", "C", "D", or "F".
  • Call that function for a few different scores and log the result to make sure it works.

The Pluralizer

  • Write a function named pluralize that:
    • takes 2 arguments, a noun and a number.
    • returns the number and pluralized form, like "5 cats" or "1 dog".
  • Call that function for a few different nouns and numbers and log the result to make sure it works.

For loops

The Grade Assigner

  • Check the results of assignGrade function from the conditionals exercise for every value from 60 to 100 - so your log should show "For 89, you got a B. For 90, you got an A.", etc.

Arrays

Your top choices

  • Create an array to hold your top choices (colors, presidents, whatever).
  • For each choice, log to the screen a string like: "My #1 choice is blue."
  • Bonus: Change it to log "My 1st choice, "My 2nd choice", "My 3rd choice", picking the right suffix for the number based on what it is.

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.