w3resource logo

CoffeeScript exercises

CoffeeScript : Display a message when a number is between a range

CoffeeScript : Exercise-6 with Solution

Write a CoffeeScript program where the program takes a random integer between 1 to 10, the user is then prompted to input a guess number. If the user input matches with guess number, the program will display a message "Matched" otherwise display a message "Not matched".

Solution :

HTML Code :

<!DOCTYPE html>
<script src="//jashkenas.github.io/coffee-script/extras/coffee-script.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>


CoffeeScript Code :

# Get a random integer from 1 to 10 inclusive
num = Math.ceil(Math.random() * 10)
gnum = prompt('Guess the number between 1 and 10 inclusive')
if gnum == num
  alert 'Matched'
  alert 'Not matched, the number was ' + num

Live Demo :

JS Bin on jsbin.com

Post your code through Disqus

Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program