To view solutions, open the file /Day1/index.html
in your browser.
Do not forget to open the Developer panel and see the section Console
.
Task:
Complete the following functions in the editor below:
- getArea(length, width): Calculate and return the area of a rectangle having sides
length
andwidth
. - getPerimeter(length, width): Calculate and return the perimeter of a rectangle having
length
andwidth
.
The values returned by these functions are printed to stdout by locked stub code in the editor.
Solution:
In js/arithmetic-operators.js
.
Task:
Implement a function named factorial that has one parameter: an integer, n
.
It must return the value of n!
(i.e., n
factorial).
Solution:
In js/functions.js
.
Task:
- Declare a constant variable,
PI
, and assign it the value Math.PI. You will not pass this challenge unless the variable is declared as a constant and named PI (uppercase). - Read a number,
r
, denoting the radius of a circle from stdin. - Use
PI
andr
to calculate thearea
andperimeter
of a circle having radiusr
. - Print
area
as the first line of output and printperimeter
as the second line of output.
Solution:
In js/let-and-const.js
.
Return to navigation list