All Tracks/lab factorial calculator/
Đang tải...
Hướng dẫn thử thách
1 / 1

Build a Factorial Calculator

A factorial is the product of an integer and all the integers below it. For example, the factorial of `5` is `5 * 4 * 3 * 2 * 1 = 120`. In this lab, you will create a factorial calculator that takes a number from the user and calculates the factorial of that number. **Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab. **User Stories:** 1. You should declare a variable `num` and assign it a number of your choice. The assigned number should be between `1` and `20` inclusive. 1. Create a function named `factorialCalculator` that takes a number as an argument and returns the factorial of that number. 1. Inside the function, declare a `result` variable and assign it the value of `1`. Using a loop, loop through all numbers from `1` to the input number(inclusive) and for each number, multiply the `result` variable by the current number and assign the result to the `result` variable. You can choose to use either a `for` loop, `while` loop or `do...while` loop here. 1. You should call the `factorialCalculator` function with `num` as the argument and assign the result to the variable `factorial`. 1. You should store the final output in the format `Factorial of [num] is [factorial]` and assign it to the variable `resultMsg`. 1. You should output the value of `resultMsg` to the console.
Vượt qua bài kiểm tra hiện tại để mở khóa bài tiếp theo.
main.js
UTF-8 • Tab Size: 2Kiểm tra bài:⌘↵
Test Output
Thử thách này không có bài test tự động. Hãy quan sát kết quả trực tiếp ở khung Preview.