Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JavaScript Follow the instructions bellow for a good rate Create a program that

ID: 3876330 • Letter: J

Question

JavaScript

Follow the instructions bellow for a good rate

Create a program that will display the result of three functions:
a) sum the elements from the Fibonacci sequence
b) divide them by randomly generated number
c) calculate factorial from the rounded result of previous operation

Functions should be stored in one, separate file. The main program should run from the app.js. Finally, a user should provide input for two variables - the number of Fibonacci items and the number responsible for the range of the randomly generated number from point b)

-----------------------------------------------------------------

Code for app.js is showen bellow:

app.js:

function calculateFibonacci(num) {
var a = 1,
b = 0,
temp;

while (num >= 0) {
temp = a;
a = a + b;
b = temp;
num--;
}

return b;
}

function displayFibonacci(s) {
var result = "";
for (i = s; i > 0; i--) {
result += calculateFibonacci(i) + ", ";
}
return result.substring(0, result.length - 2);
}

console.log(displayFibonacci(21));

--------------------------------------------------------------------

Output in Console:

17711, 10946, 6765, 4181, 2584, 1597, 987, 610, 377, 233, 144, 89, 55, 34, 21, 13, 8, 5, 3, 2, 1
[Finished in 0.9s]

Explanation / Answer

function sumFib(num)

{

var a = 1,

b = 0,

temp,

sum=0;

while (num >= 0) {

temp = a;

a = a + b;

b = temp;

sum+=a;

num--;

}

return sum;

}

function div(num)

{

var c= rand(int);

var result=num/c;

return result;

}

These are the algorithm of the first two functions you need. Hope it will help you code properly :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote