Using the switch statement

…Switch statements are one of those things…that I don't use really much in JavaScript.…The syntax is extremely messy.…I never like how you had to add a break statement at the end of every switch.…It just looked really messy.…Now, the switch statement is designed to allow you…to execute commands depending on the value of an element.…So, let's see how that works in how you use em in Coffee Script.…So, let's go ahead and add a function here called append.…And it's going to take a value called item.…So, this is just going to go to the…content and just append whatever we pass into it.…

So, I'll use string interpolation here and a pass along item.…Then I'm going to create here an author and set it to a value.…So, I'll just create an author called Bob here, set it to an author.…And then I'm going to create a switch…with the coffee script version of the statement.…So, all you do is you say, switch and then you put in what you want to test.…And you pretty much use English like commands.…You say, when and then a value here, when the…

Resume Transcript Auto-Scroll

Author

Released

3/28/2014

Learning CoffeeScript allows front-end developers to write JavaScript more beautifully and efficiently. It gives your code an extra zing. This course teaches the best features from the CoffeeScript language, like splats and ranges, plus how to write common JavaScript commands more efficiently using CoffeeScript. Author Ray Villalobos also shows how to work with Gulp.js, a streaming build system for not only CoffeeScript, but also Sass, LESS, JavaScript, and CSS.

Topics include:

What is CoffeeScript?

Setting up a project with Gulp.js

Adding CoffeeScript to your workflow

Dealing with array ranges

Working with conditional statements

Using loops

Working with splats

Skill Level Intermediate

1h 48m

Duration

66,630

Views

Show MoreShow Less

Q: Setting up LiveReload doesn't work as explained. What should I do?

A: The small plugins for Gulp (like LiveReload) update all of the
time and sometimes there are slight differences from when the courses
were originally recorded. If you want to use the course as is, you can use the following in your package.json document.

{

"name": "myApp",

"version": "0.1.0",

"description": "Sample app",

"author": "Ray Villalobos",

"devDependencies": {

"gulp-livereload": "~1.1.1",

"gulp-ruby-sass": "~0.3.0",

"gulp-coffee": "~1.4.1",

"gulp-uglify": "~0.2.1",

"gulp-concat": "~2.1.7"

}

}

The correction is located at https://github.com/planetoftheweb/coffeescript. It
uses the current versions of all of the plugins including
gulp-livereload. If you want to use the newer versions of the plugins,
you can compare the Gulp file in GitHub to what’s in the course.
Every one of the branches in the course has been updated.