Question

Fibonacci Sequence (Javascript in HTML)   function fib(first, second, countdown){     console.log("I was called with " + first...

Fibonacci Sequence (Javascript in HTML)

  function fib(first, second, countdown){

    console.log("I was called with " + first + ", " + second + ", " + countdown);

        if(countdown>0){

                                fib(first,first+second, countdown-1);

        }

    }

    fib(1,2,3);

Now you get to figure out how to use the fib function to print the number sequence without using a loop in the function (hint, the function needs to call itself). How is this exactly done? It needs to be in written so I can input it into my visual style code which is set up for html.

Homework Answers

Answer #1

CODE SCREENSHOT

CODE TEXT

// function to print the nth term of a fibonacci series

function fib(num) {

// if the value of n < 2, return the value of n

// this is the base case

if(num < 2) {

return num;

}

// otherwise perform recursion

else {

return fib(num-1) + fib(num - 2);

}

}

console.log(fib(6))

OUTPUT

Know the answer?
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
Similar Questions
Please Write the whole program in assembly i am able to calculate the fibonacci series but...
Please Write the whole program in assembly i am able to calculate the fibonacci series but not sure how to print it in reverse order. Please give a Complete code !! Programming Exercise 1 (10 points): [call it Ass2-Q1.asm] Write an ASM program that reads an integer number N and then displays the first N values of the Fibonacci number sequence, described by: Fib(0) = 0, Fib(1) = 1, Fib(N) = Fib(N-2) + Fib(N-1) Thus, if the input is N...
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>All Pets Veterinary Hospital</title> <style> body { font-family: arial,...
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>All Pets Veterinary Hospital</title> <style> body { font-family: arial, sans-serif; font-size: 100%; } /* outer container */    #wrapper { width: 960px; margin: 50px auto; padding: 0px; background-color: rgb(255, 255, 255); /* white */ border: 1px solid #000; /* black */ }    header h1 { text-align: center; }    nav { text-align: center; background: rgb(175, 196, 206); }    address figure { text-align: center; } </style> </head> <body> <div id="wrapper"> <!-- outer...
The code I have written runs but I need it us UDP not TCP. Also I...
The code I have written runs but I need it us UDP not TCP. Also I just need someone to check my work and make sure that it works properly. The python code needs to be run with command line so you can add more than one client. The directions: 1. The chat is performed between 2 clients and not the server. 2. The server will first start up and choose a port number. Then the server prints out its...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int...
Write a Python 3 program called “parse.py” using the template for a Python program that we...
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file. Name your output file “output.txt”. Build your program using a main function and at least one other function. Give your input and output file names as command line arguments. Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:...
New Wave Music New Wave Music is an international company that develops music software that is...
New Wave Music New Wave Music is an international company that develops music software that is used to compose music, play recordings in clubs, and produce albums. Founder and CEO Moritz Halbach is the company’s biggest fan. He said “I started this company from nothing, just me, my ideas, and my computer. I love music---love playing music, love writing programs for making music, love listening to music---and the money is nice, too.” Moritz says that he never wanted to work...
There are two reflective essays from MED students during their third year internal medicine clerkship. One...
There are two reflective essays from MED students during their third year internal medicine clerkship. One student sees each connection to a patient as like the individual brush strokes of an artist and the other sees gratitude in a patient with an incurable illness and is moved to gratitude in her own life. (WORD COUNT 500) Reflect on both essays and then choose one and describe how the student grew from the experience. Then explain what you learned as a...
URGENT!! 6 Multiple Choice Questions with the correct answers from the article below. Authenticity has become...
URGENT!! 6 Multiple Choice Questions with the correct answers from the article below. Authenticity has become the gold standard for leadership. But a simplistic understanding of what it means can hinder your growth and limit your impact. Consider Cynthia, a general manager in a health care organization. Her promotion into that role increased her direct reports 10-fold and expanded the range of businesses she oversaw—and she felt a little shaky about making such a big leap. A strong believer in...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT