Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7079303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:39:21+00:00 2026-05-28T06:39:21+00:00

I am new to coffee scripting..This is my first script and is not working..

  • 0

I am new to coffee scripting..This is my first script and is not working..

html
 head title='hello world'
  css:
   h1{
    color: blue;
    }
  coffee:
     number   = 42
     opposite = true
     saybye = () ->
      alert 'hello'+number
      ''        
body
  h1 
   |hello world
  input type="button" onclick="saybye()" value="sayhello"

scss:
 $blue: #3bbfce;

 h2{
  color: $blue;
 } 

It says saybye is not found and should I always end with some expression which will get return. Is there a way to stop the return call?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:39:22+00:00Added an answer on May 28, 2026 at 6:39 am

    I don’t know what Slim does but CoffeeScript usually gets wrapped in a function to avoid namespace pollution. So, your CoffeeScript probably ends up being converted to JavaScript something like this:

    (function() {
      var number, opposite, saybye;
    
      number = 42;
    
      opposite = true;
    
      saybye = function() {
        alert('hello' + number);
        return '';
      };
    })();
    

    The result is that saybye is not visible to your HTML.

    You really shouldn’t be using onclick in 2012, you should be binding to the event through the modern API. If you’re using jQuery, you’d do it like this:

    coffee:
      number   = 42
      opposite = true
      saybye = () ->
        alert 'hello'+number
        ''  
      $ -> $('input[type=button]').click saybye
    

    If you’re not using jQuery (or similar), then you’d do it the hard way using addEventListener on the raw DOM object. Alternatively, you could put them in window yourself and bypass scope protection:

    coffee:
      window.number   = 42
      window.opposite = true
      window.saybye   = () ->
        alert 'hello' + number
    

    As far as returning something goes, don’t worry about it, return whatever makes sense. Sometimes returning undefined makes sense, sometimes it doesn’t. If there is no obvious return value then just let CoffeeScript do what it wants, go with this:

    saybye = () ->
      alert 'hello' + number
    

    and move on to more interesting problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Based on this example (which works): var Comment = new Schema(); Comment.add({ title :
This probably has a simple answer, but I must not have had enough coffee
No coffee. Brain. Not. Functioning. I have this linq query here: Public Function ListAllVisitDates()
First of all, im new here, and im (not) a pro ;) (but i
New to javascript/jquery and having a hard time with using this or $(this) to
new Date(05-MAY-09 03.55.50) is any thing wrong with this ? i am getting illegalArgumentException
When I run rails new app...I get this error /Library/Ruby/Site/1.8/rubygems/specification.rb:542:in `read': Permission denied -
I'm fairly new to Objective-C and am not sure how to correctly deal with
Since my other bug got solved, I'm posting a new question for this bug.
I'm trying to create methods dynamically in coffee script, but as my code shows,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.