The following is my notes for the challenges on level 5 of of CodeSchool's CoffeeScript course (https://www.codeschool.com/courses/coffeescript).
********* challenge 5.1 # jQuery(function($){ # $('.drink a').click(function(){ # var newStyle = { # 'color': '#F00', # 'font-weight': 'bold' # }; # $(this).css(newStyle) # }); # }); jQuery ($) -> $('.drink a').click -> var newStyle = 'color': '#F00' 'font-weight': 'bold' $(@).css newStyle
********* challenge 5.2 $('.drink a').click (e) -> e.preventDefault() alert $(@).text() ————— coffeeList = init: -> $('.drink a').click (e) -> e.preventDefault() alert $(@).text() coffeeList.init()
********* challenge 5.3 # $.ajax({ # url: '/coffeeList', # method: 'GET', # success: function(results) { # var i = null # , coffee = null; # for (i = 0; i 3) { # $('ul.drink').append("<li>" + coffee.name + "</li>") # } # } # }, # error: function(results) { # alert("failure " + results); # } # }); $.ajax({ url: '/coffeeList' method: 'GET' success: (results) -> $('ul.drink').append("<li>#{coffee.name}</li>") for coffee in results when coffee.level > 3 error: (results) -> alert "failure #{results}" })
File: