Git Product home page Git Product logo

01-even-or-odd's Introduction

Background & Objectives

Today is your first day of JavaScript. The goal of this first day is for you to realize that it's a programming language, like Ruby. It has variables, functions, conditions, loops, etc.

Today we won't need the browser. Instead, we'll use Node.js to execute some JavaScript directly in our terminal.

Make sure that the following command returns a version greater than 10:

node -v

If not, Node might not be installed on your system. Please have a look at the Setup section in the lecture slides.

Install Eslint Sublime Linter

Before starting, take the time to install Eslint Sublime Linter in Sublime Text:

  1. Open Sublime Text
stt
  1. In Sublime Text, open Package Control's menu:
# macOS
cmd shift p

# Ubuntu
ctrl shift p
  1. Type install package and select Package Control: Install Package
  2. Type SublimeLinter-eslint and select it
  3. Restart Sublime Text

It will highlight instantly your syntax errors / style offenses in Sublime Text. Picking up the JavaScript syntax after Ruby may be tricky, so this should help you a lot.

Specs

Let's start with a very simple algorithm. Open the lib/even_or_odd.js file. Implement the evenOrOdd function which takes one parameter number (of type Number) and returns a String:

  • "even" if the number is even (0, 2, 4, etc.)
  • "odd" if the number is odd (1, 3, 5, etc.)

โš ๏ธ Warning: In JavaScript, you need to explicitly write the return keyword, otherwise the function will return undefined! The only exception to this rule is when you use a one-liner arrow function with implicit return.

Hint: remember the Ruby modulo operator? It also exists in JavaScript and might be useful!

Run rake to check your style and the correctness of your function!

Once the first exercise is all green (style + tests), please commit and push ๐Ÿ™

About the testing setup

Open the Rakefile in Sublime Text. You will find two tasks:

These two commands are run from the node_modules folder. It was created by running yarn install in the 04-FrontEnd folder (cd ../..), reading the package.json file (open it!).

01-even-or-odd's People

Contributors

hankhng avatar

Watchers

 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.