w3resource logo


CoffeeScript exercises

CoffeeScript function: Compute the value of bn where n is the exponent and b is the bases

CoffeeScript Function : Exercise-19 with Solution

Write a CoffeeScript function to compute the value of bn where n is the exponent and b is the bases. Accept b and n from the user and display the result.

Solution :

HTML Code :

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>

</body>
</html>

CoffeeScript Code :

ub = Number(prompt('Input a base number.', '0'))
un = Number(prompt('Input an exponent.', '0'))

exp = (b, n) ->
  ans = 1
  i = 1
  while i <= n
    ans = b * ans
    i++
  ans

alert exp(ub, un)

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