From the course: Learning CoffeeScript
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Using the switch statement - CoffeeScript Tutorial
From the course: Learning CoffeeScript
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,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Basic CoffeeScript syntax7m 15s
-
(Locked)
Using realistic assets5m 24s
-
(Locked)
Understanding variables10m 11s
-
(Locked)
Dealing with array ranges4m
-
(Locked)
Working with conditional statements5m 2s
-
(Locked)
Using loops and comprehensions4m 14s
-
(Locked)
Adding basic functions2m 57s
-
(Locked)
Working with splats3m 28s
-
(Locked)
Using the switch statement2m 51s
-
(Locked)
Using aliases for "this" and other tidbits3m 57s
-
(Locked)
-