Question

Question 1: What port is this application running on? Question 2: How many function definitions do...

Question 1: What port is this application running on?

Question 2: How many function definitions do you see in this program? List the function names. If it’s an anonymous function write the function definition.

Question 3: How many global variables are there in this program? What are they? (Hint: Some are programmer defined using keyword var and some provided by JavaScript language implicitly.)

var http = require('http');

// function to calculate rabbit reproduction using fibonacci sequence
function fibonacci(n) {
    if (n < 2)
        return 1;
    else
        return
fibonacci(n - 2) + fibonacci(n - 1);
}

var server = http.createServer(function (request, response) {
    if (request.method == 'GET' && request.url == '/') {
        response.write('<!DOCTYPE html>');
        response.write('<html>');
        response.write('<head><title>Rabbit Population Forcast</title></head>');
        response.write('<body>');
        response.write('<h1>Rabbit Population Forecast</h1>')
        response.write('<div><iframe width="560" height="315" src="https://www.youtube.com/embed/koFsRrJgioA" frameborder="0" allowfullscreen></iframe></div>')
        response.write('<ul>');
        response.write('<li><a href="/1m">1 month population</a></li>');
        response.write('<li><a href="/10m">10 months population</a></li>');
        response.write('<li><a href="/30m">30 months population</a></li>');
        response.write('<li><a href="/44m">44 months population</a></li>');
        response.write('</ul>');
        response.write('</body>');
        response.write('</html>');
        response.end();
    } else if (request.method == 'GET' && request.url == '/1m') {
        response.write('<!DOCTYPE html>');
        response.write('<html>');
        response.write('<head><title>Rabbit Population Forcast</title></head>');
        response.write('<body>');
        console.time('1m_timer');
        response.write('<p style="color: red">Pairs of rabbits after 1 month is: ' + fibonacci(1) + '</p>');
        console.timeEnd('1m_timer')
        response.write('<h1>Rabbit Population Forecast</h1>')
        response.write('<div><iframe width="560" height="315" src="https://www.youtube.com/embed/koFsRrJgioA" frameborder="0" allowfullscreen></iframe></div>')
        response.write('<ul>');
        response.write('<li><a href="/1m">1 month population</a></li>');
        response.write('<li><a href="/10m">10 months population</a></li>');
        response.write('<li><a href="/30m">30 months population</a></li>');
        response.write('<li><a href="/44m">44 months population</a></li>');
        response.write('</ul>');
        response.write('</body>');
        response.write('</html>');
        response.end();
    } else if (request.method == 'GET' && request.url == '/10m') {
        response.write('<!DOCTYPE html>');
        response.write('<html>');
        response.write('<head><title>Rabbit Population Forcast</title></head>');
        response.write('<body>');
        console.time('10m_timer');
        response.write('<p style="color: red">Pairs of rabbits after 10 months is: ' + fibonacci(10) + '</p>');
        console.timeEnd('10m_timer');
        response.write('<h1>Rabbit Population Forecast</h1>')
        response.write('<div><iframe width="560" height="315" src="https://www.youtube.com/embed/koFsRrJgioA" frameborder="0" allowfullscreen></iframe></div>')
        response.write('<ul>');
        response.write('<li><a href="/1m">1 month population</a></li>');
        response.write('<li><a href="/10m">10 months population</a></li>');
        response.write('<li><a href="/30m">30 months population</a></li>');
        response.write('<li><a href="/44m">44 months population</a></li>');
        response.write('</ul>');
        response.write('</body>');
        response.write('</html>');
        response.end();
    } else if (request.method == 'GET' && request.url == '/30m') {
        response.write('<!DOCTYPE html>');
        response.write('<html>');
        response.write('<head><title>Rabbit Population Forcast</title></head>');
        response.write('<body>');
        console.time('30m_timer');
        response.write('<p style="color: red">Pairs of rabbits after 30 months is: ' + fibonacci(30) + '</p>');
        console.timeEnd('30m_timer');
        response.write('<h1>Rabbit Population Forecast</h1>')
        response.write('<div><iframe width="560" height="315" src="https://www.youtube.com/embed/koFsRrJgioA" frameborder="0" allowfullscreen></iframe></div>')
        response.write('<ul>');
        response.write('<li><a href="/1m">1 month population</a></li>');
        response.write('<li><a href="/10m">10 months population</a></li>');
        response.write('<li><a href="/30m">30 months population</a></li>');
        response.write('<li><a href="/44m">44 months population</a></li>');
        response.write('</ul>');
        response.write('</body>');
        response.write('</html>');
        response.end();

Homework Answers

Answer #1

Ans 1) Port no. 80
Explanation: As given in first line the application is using http protpcol. As no specific port number is mentioned, the
application run on default port number of http i.e port no. 80.

Ans 2)
There are two functions are defined in the given code.
1. fibonacci (named function)- Fibonacci is the first named function in this program, which is recursive in nature and gives the fibonacci series.
2. server (anonymous function)- var server is a variable name to which an anonymous function is assigned.

Ans 3)
There are total 3 variables that are declared in this code snippet. They are-
http: variable created to load and cache javascript module named 'http'
n: variable created to calculate fibonacci series of a number 'n'.
server: this variable is created for anonymous function.

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
Challenge 5 Read ALL of the instructions carefully before starting the exercise! Dear Colleague, Earlier today...
Challenge 5 Read ALL of the instructions carefully before starting the exercise! Dear Colleague, Earlier today I built my fourth website using HTML5 and CSS3. This time I wanted to try using CSS float layout options on a website dedicated to my favorite topic: robotics. I wanted my website to look like what is shown in Figure 1 (see below). However, after giving it my best effort, things once again didn’t turn out the way I wanted (see the code...
This will be my third time submitting this question. THERE SHOULD BE NO USE OF CSS...
This will be my third time submitting this question. THERE SHOULD BE NO USE OF CSS OR SWITCH STATEMENTS IN THE JAVASCRIPT. Even though there is stylesheet in the HTML file do no create a new one. Project Standards: Students will use click events to capture user input. Students will use variables to store information needed by their application and keep track of their program’s state. Students will use conditionals to control project flow. Project Task You will be building...
TASK 2: Open numberic-variable_problem.js file in a text editor (e.g., NotePad++). What is the syntax error...
TASK 2: Open numberic-variable_problem.js file in a text editor (e.g., NotePad++). What is the syntax error in the JavaScript file? Find error message in console in a browser’s developer tool. Fix that error and reload the web page in browser. What is the change in the content displayed in the web page after fix the syntax error in the JavaScript code? Replace the line#18 statement (el.textContent = '$' + total;) in the JavaScript code with    el.textContent = '$' + total.toFixed(3);...
In the previous assessment, you used a static set of named variables to store the data...
In the previous assessment, you used a static set of named variables to store the data that was entered in a form to be output in a message. For this assessment, you will use the invitation.html file that you modified in the previous assessment to create a more effective process for entering information and creating invitations for volunteers. Rather than having to enter each volunteer and create an invitation one at a time, you will create a script that will...