Convert the commented jQuery code below to CoffeeScript.app
# jQuery(function($) { # $('#newCoffee a').click(function() { # alert('New coffee added'); # }); # }); jQuery ($) -> $("#newCoffee a").click -> alert('New coffee added')
Convert the commented jQuery code below to CoffeeScript and use CoffeeScript-style string interpolation.ide
# $('#newCoffee a').click(function() { # var name = prompt('Name of coffee:'); # alert("New coffee added: " + name); # }); $("#newCoffee a").click -> name = prompt('Name of coffee:') alert("New coffee added: #{name}")
Convert the commented jQuery to CoffeeScript and use CoffeeScript-style string interpolation.this
# $('#newCoffee a').click(function() { # var coffee, name; # name = prompt('Name of coffee:'); # coffee = $("<li>" + name + "</li>"); # $('ul.drink').append(coffee); # }); $("#newCoffee a").click -> name = prompt('Name of coffee') coffee = $("<li> #{name} </li>") $('ul.drink').append(coffee);
Convert the commented jQuery code below to CoffeeScript. Use @ instead of this.spa
# $('.drink li a').click(function(e) { # e.preventDefault(); # alert($(this).text()); # }); $('.drink li a').click (e) -> e.preventDefault(); alert($(@).text());
Convert the commented jQuery code below to CoffeeScriptcode
# $('.drink li').mouseenter(function() { # $(this).find('span').show(); # }); # $('.drink li').mouseleave(function() { # $(this).find('span').hide(); # }); $('.drink li').mouseenter -> $(@).find('span').show() $('.drink li').mouseleave -> $(@).find('span').hide()
Convert the commented jQuery code below to CoffeeScript.blog
//The hover function takes two functions as its arguments, like so: $('selector').hover( -> $(@).find('span').show(); -> $(@).find('span').hide(); )
# $('.drink li').hover(function() { # $(this).find('span').show(); # }, function() { # $(this).find('span').hide(); # }); $('.drink li').hover( -> $(@).find('span').show(); -> $(@).find('span').hide(); )