A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3resource.com/coffeescript-exercises/coffeescript-exercise-6.php below:

Website Navigation


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

CoffeeScript: Display a message when a number is between a rangeLast update on August 19 2022 21:51:24 (UTC/GMT +8 hours) 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>
<html>
<head>
<script src="//jashkenas.github.io/coffee-script/extras/coffee-script.js"></script>
  <meta charset="utf-8">
  <title>Display a message when a number is between a range</title>
</head>
<body>

</body>
</html>

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
  console.log 'Matched'
else
  console.log 'Not matched, the number was ' + num

Sample Output:

"Not matched, the number was 8"

Live Demo :

See the Pen coffeescript-exercise-6 by w3resource (@w3resource) on CodePen.

Improve this sample solution and post your code through Disqus.




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4