Question

JavaScript Just use javascript, dont include HTML Follow the instructions bellow for a good rate Create...

JavaScript

Just use javascript, dont include HTML

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 that is provided bellow, the other file should be called module.js that includes the function above. 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 Console for app.js:

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]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

module.js :

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

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

return b;
}

function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}

// 1st method
function fibonacciSum(numOfFibonacciItems) {
var sumOfFibonacci = 0;
for(var i = 1; i <= numOfFibonacciItems; i++) {
sumOfFibonacci += calculateFibonacci(i); // calling function of app.js
}
console.log("Sum Of Fibonacci : "+sumOfFibonacci);
return sumOfFibonacci;
}

// 2nd method
function divideByRandom(sumOfFibonacci, maxRandomRange) {
var randomNumber = getRandomInt(maxRandomRange);
var afterDividing = sumOfFibonacci/randomNumber;
console.log("After dividing by random number : "+afterDividing);
return afterDividing;
}

// 3rd method
function factorial(n) {
if (n === 0) {
return 1;
}
return n * factorial(n - 1);
}

// this is required funtion
export function display(numOfFibonacciItems, maxRandomRange){
var sumOfFibonacci = fibonacciSum(numOfFibonacciItems);

var afterDividing = divideByRandom(sumOfFibonacci, maxRandomRange);

var fact = factorial(Math.floor(afterDividing));

console.log("Factorial : "+fact);

}

app.js :

import {display} from './module';

display(7,5);

Add a comment
Know the answer?
Add Answer to:
JavaScript Just use javascript, dont include HTML Follow the instructions bellow for a good rate Create...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JavaScript - Build with Node.js Follow the instructions bellow for a good rate Create a program...

    JavaScript - Build with Node.js Follow the instructions bellow for a good rate Create a program that will add, remove, get and display all items, stored in JSON file, based on user input (i.e. using yargs). You should choose your own individual purpose - it can be a warehouse, ticketing system, grading book, etc. Make sure you create an appropriate JSON object with real-life parameters - for example for user registration system you should use id, email, and a name....

  • NEED HELP with HTML with Javascript embedding for form validation project below. I have my code...

    NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...

  • C Language program. Please follow the instructions given. Must use functions, pointers, and File I/O. Thank...

    C Language program. Please follow the instructions given. Must use functions, pointers, and File I/O. Thank you. Use the given function to create the program shown in the sample run. Your program should find the name of the file that is always given after the word filename (see the command line in the sample run), open the file and print to screen the contents. The type of info held in the file is noted by the word after the filename:...

  • Programming Assignment #2 EE 2372 MAKE SURE TO FOLLOW INSTRUCTIONS CAREFULLY, IF YOU HAVE ANY DOUBTS...

    Programming Assignment #2 EE 2372 MAKE SURE TO FOLLOW INSTRUCTIONS CAREFULLY, IF YOU HAVE ANY DOUBTS PLEASE EMAIL ME! This programming assignment will just be a small extension to programming assignment 1. In the first assignment each of the functions could only take a predefined number of inputs. This time the objective is to be able to complete these functions with any amount of inputs. The user will pass arguments through the command line (this means you will have to...

  • 1. You are given a C file which contains a partially completed program. Follow the instructions...

    1. You are given a C file which contains a partially completed program. Follow the instructions contained in comments and complete the required functions. You will be rewriting four functions from HW03 (initializeStrings, printStrings, encryptStrings, decryptStrings) using only pointer operations instead of using array operations. In addition to this, you will be writing two new functions (printReversedString, isValidPassword). You should not be using any array operations in any of functions for this assignment. You may use only the strlen() function...

  • I need a basic program in C to modify my program with the following instructions: Create...

    I need a basic program in C to modify my program with the following instructions: Create a program in C that will: Add an option 4 to your menu for "Play Bingo" -read in a bingo call (e,g, B6, I17, G57, G65) -checks to see if the bingo call read in is valid (i.e., G65 is not valid) -marks all the boards that have the bingo call -checks to see if there is a winner, for our purposes winning means...

  • in c++ please Page 1 of 3 (PRO) Project Assignment Instructions Last Charged: 6/1/2020 Read and...

    in c++ please Page 1 of 3 (PRO) Project Assignment Instructions Last Charged: 6/1/2020 Read and follow the directions below carefully and perform the steps in the order listed. You will be solving one program as instructed and turning in your work electronically via an uploaded file within Eagle Online/Canvas and copy & paste the program to the Text Entry box as well. Make sure and check your work prior to uploading the assignment (NOTE: For Steps 1 & 2...

  • Using C++ in Visual Studios Rewrite the code to use a Stack instead of a Queue....

    Using C++ in Visual Studios Rewrite the code to use a Stack instead of a Queue. You will need to think about the differences in the Stack and Queue. Think about how they operate and how the nodes may differ.   Modify the code as necessary. You will need to push to the Stack, pop from the Stack, peek at the Stack. You will need a member functions like in the example code. Your program will need to show that everything...

  • CAN SOMEONE PLEASE HELP AND ANSWER THIS Introduction to computing and IT question --------------------------------------...

    CAN SOMEONE PLEASE HELP AND ANSWER THIS Introduction to computing and IT question ---------------------------------------------------------------------------------------------------------------------------------------------------------------- this is the file required for the question Question 4 (14 marks) This question assesses Block 2 Part 4 a. This part of the question involves creating two drawings. You can make your drawings whichever way is easiest or fastest for you. For instance, you could simply make your drawings using pencil and paper then scan or photograph them. Consider the following two assignments: o languages-['java',...

  • use the code and change it Task This assignment is very straight-forward and quick to do...

    use the code and change it Task This assignment is very straight-forward and quick to do since BigInteger supports integer operations just as long does! Start by downloading the code below (scroll down). (Certainly compile and run the code to see what it does.) Add "import java.math.BigInteger;" to the top of the file. Replace all "Long" types with "BigInteger" in the entire file. (This works because long was intentionally only used for computed values.) Replace all "long" types with "BigInteger"...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT