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.
HTML Code :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="//jashkenas.github.io/coffee-script/extras/coffee-script.js"></script>
<title>Compute the value of bn where n is the exponent and b is the bases</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
console.log exp(ub, un)
Sample Output:
If base=2, exponent=4 then 16
Live Demo :
See the Pen coffeescript-exercise-19 by w3resource (@w3resource) on CodePen.
Improve this sample solution and post your code through Disqus.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework