Code Monkey home page Code Monkey logo

f1-13-overly-excited's Introduction

Overly Excited

Requirements

For this exercise, you need to create a single JavaScript function named addExcitement that will use console.log() to print out a sentence to the browser console.

  1. If you haven't done so yet, create the workspace/exercises/overly-excited directory structure in your home directory. Open your terminal and enter in the following command.

    mkdir -p ~/workspace/exercises/overly-excited
    
  2. Now that you have created the directory, you want to change to that directory so that you can add files to it.

    cd ~/workspace/exercises/overly-excited
    
  3. Create an index.html file with the touch command.

  4. Create an overly-excited.js file with the touch command.

  5. Copy the following code and paste it into the index.html file. Notice that the overly-excited.js file is properly linked so that when you load this HTML file in a web browser, the logic in that file will be executed.

    <!DOCTYPE html>
    <html>
    <head>
        <title>Overly Excited</title>
    </head>
    <body>
    
        <script src="overly-excited.js"></script>
    </body>
    </html>
    
  6. Open the index.html file in your web browser.

  7. At this point, you will simply see a blank web page because you have no content in the HTML file. Open your developer tools using the Option+Command+I keyboard shortcut.

  8. At the top of the developer tools panel, you will see the word Console. Click on that word. The console.log() statement will output any message into this panel in your developer tools. You can try it out immediately by clicking in the Console panel, and typing console.log("Hello, world!"), and then pressing your return key.

Stacking Words

Create an addExcitement function that should console.log() rows of words. It should take an array containing the words of a sentence and output them in the developer console.

Example output:

The
The walrus
The walrus danced
The walrus danced through
The walrus danced through the
The walrus danced through the trees
The walrus danced through the trees in
The walrus danced through the trees in the
The walrus danced through the trees in the light
The walrus danced through the trees in the light of
The walrus danced through the trees in the light of the
The walrus danced through the trees in the light of the moon
...

Paste the following code into overly-excited.js

// Create an array that contains the words in the sentence
var sentence = [];

// The addExcitement function should accept the array as the sole argument
function addExcitement (theWordArray) {
    /*
      Write a `for` loop that iterates over the array argument and
      outputs the words.
     */
}

// Invoke the function and pass in the array
addExcitement(sentence)

Adding Conditions to the Loop

Then add logic to addExcitement that places an exclamation point (!) after every third word. This will require you to do some basic math in JavaScript, and use an if statement.

Your job is to read the following English statement and write the equivalent in JavaSript code to make it work.

If the current value of the [counter variable] can be evenly divided by 3 - using the JavaScript [remainder] operator - then add a single exclamation point (!) to the output.

SEE ALSO: 
- FOR LOOPS: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for
- REMAINDER:  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Remainder

Example output:

The
The walrus
The walrus danced!
The walrus danced! through
The walrus danced! through the
The walrus danced! through the trees!
The walrus danced! through the trees! in
The walrus danced! through the trees! in the
The walrus danced! through the trees! in the light!
The walrus danced! through the trees! in the light! of
The walrus danced! through the trees! in the light! of the
The walrus danced! through the trees! in the light! of the moon!
...

Challenge

Add logic in the addExcitement function to the increase the number of exclamation points after every third word. The number of exclamation points (!) will be determined by how many times the counter variable can be divided by 3.

Example output:

The
The walrus
The walrus danced!
The walrus danced! through
The walrus danced! through the
The walrus danced! through the trees!!
The walrus danced! through the trees!! in
The walrus danced! through the trees!! in the
The walrus danced! through the trees!! in the light!!!
The walrus danced! through the trees!! in the light!!! of
The walrus danced! through the trees!! in the light!!! of the
The walrus danced! through the trees!! in the light!!! of the moon!!!!
...

f1-13-overly-excited's People

Contributors

edwardrz avatar

Watchers

James Cloos avatar

f1-13-overly-excited's Issues

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.