GithubHelp home page GithubHelp logo

gerardmi24 / fewpjs-fns-as-first-class-data-do-behavior-nyc01-seng-ft-082420 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from learn-co-students/fewpjs-fns-as-first-class-data-do-behavior-nyc01-seng-ft-082420

0.0 0.0 0.0 5.24 MB

License: Other

HTML 17.32% JavaScript 82.68%

fewpjs-fns-as-first-class-data-do-behavior-nyc01-seng-ft-082420's Introduction

JavaScript Functions as First Class Data: Do behavior

Learning Goals

  • Create a JavaScript function triggered by an event

Introduction

In JavaScript, functions are what's known as first-class citizens of the language. This means they can be treated like any other variable: they can be assigned to a variable, stored in a data structure, passed as an argument to another function, or be the return value of another function. In this lab, we're going to have an event handler send some information gathered by an <input> field to a helper function.

Create a "First-Class" Function

We're going to create a web greeting! You're provided a text input field in which you should enter a time in 24 hour time. When you click the Submit button, some provided code will run which will make calls to two functions.

The greet() function

The greet function should take one argument, a String which specifies the 24-hour time in the format HH:MM.

  • If the time is earlier than 12pm, return "Good Morning".
  • If the time is between 12pm and 5pm, return "Good Afternoon".
  • If the time is later than 5pm, return "Good Evening".

NOTE: The value returned from the <input> will be of type String. You’ll need to take the String of the 24 hour time and convert it to a number. The split() function and parseInt() function should help.

The displayMessage() function

The displayMessage function should take one argument, a String.

When the function runs it should update the text inside the #greeting node with the content of the argument.

It does not return anything.

Testing

Finally, open up your index.html file in the browser. After typing 15:00 in the input field and pressing the Submit button should, you should see "Good Afternoon" printed on the DOM.

Did it work? If so, take time to celebrate! Don't move on yet! Take some time to digest and internalize the code you've just wrote. If not, take time to debug.

Conclusion

This lab demonstrates just the tip of the iceberg when it comes to leveraging the power of JavaScript functions. There are heaps of features that JavaScript has — some are even comparable to Ruby and other programming languages. We'll be exploring more on JavaScript events in the next lesson.

fewpjs-fns-as-first-class-data-do-behavior-nyc01-seng-ft-082420's People

Contributors

cjbrock avatar dependabot[bot] avatar drakeltheryuujin avatar geluso avatar gerardmi24 avatar jenmyers avatar lizbur10 avatar maxwellbenton avatar rrcobb avatar sgharms avatar thuyanduong avatar thuyanduong-flatiron 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.