0% found this document useful (0 votes)
3K views3 pages

1.try-It-Out - Function For Fibonacci Series Welcome To To Generate Fibonacci Sequence New

The document contains 5 code snippets for JavaScript functions: 1. A function to generate the Fibonacci sequence up to a given input number. 2. A function to retrieve user registration details inputted in form fields and return them in a single string. 3. A function to dynamically add new options to a dropdown country field from an input textbox. 4. A function to generate a random character string of a given length. 5. Functions to update a calculator display, evaluate the displayed calculation, and reset the display.

Uploaded by

Stark
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3K views3 pages

1.try-It-Out - Function For Fibonacci Series Welcome To To Generate Fibonacci Sequence New

The document contains 5 code snippets for JavaScript functions: 1. A function to generate the Fibonacci sequence up to a given input number. 2. A function to retrieve user registration details inputted in form fields and return them in a single string. 3. A function to dynamically add new options to a dropdown country field from an input textbox. 4. A function to generate a random character string of a given length. 5. Functions to update a calculator display, evaluate the displayed calculation, and reset the display.

Uploaded by

Stark
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

https://www.notesbureau.com/2022/05/javascript-essentials-fp-mcqs-answers.

html

1.Try-it-out - Function for Fibonacci Series


Welcome to To generate Fibonacci sequence new
process.stdin.resume();
process.stdin.setEncoding('utf-8');

var __input_stdin = "";


var __input_stdin_array = "";
var __input_currentline = 0;

process.stdin.on('data', function(data) {
    __input_stdin += data;
});

/*
 * Complete the function below.
 */
function fibonacciSequence(input) {
    //Type your code here.
        var n1=0;
        var n2=1;
        var out=[];
        if(input==1)
            out.push(n1);
        else if(input==2)
            out.push(n1,n2);
        else{
            out.push(n1,n2);
            for(var i=0;i<=input-2;i++){
                var n3=n2+n1;
                n1=n2;
                n2=n3;
                out.push(n3);
      }
    }
        return out;
}
var fs = require('fs');
var wstream = fs.createWriteStream(process.env.OUTPUT_PATH);
process.stdin.on('end', function() {
    __input_stdin_array = __input_stdin.split("\n");
    var input;
    var input = parseInt(__input_stdin_array[__input_currentline].trim(), 10);
    __input_currentline += 1;

    res = fibonacciSequence(input);
    for(var res_i = 0; res_i < res.length; res_i++) {
        wstream.write(res[res_i]+"\n");
  }

    wstream.end();
});

2.Try-it-out - DOM - User Registration Details


Welcome to To read the user registration details
File Name - index.js

function myFunction() {
 var name = document.getElementById("myname").value;
 var phone = document.getElementById("myphone").value;
 var country = document.getElementById("mycontry").value;
 var email = document.getElementById("mymail").value;
 var result = name + "," + phone + "," + country + "," + email;
 alert(result);
 return result;
}
3.Try-it-out - DOM - Create Drop Down Country Field
Welcome to To create a drop down Country field
File Name - index.js

function runList(){
   var select = document.getElementById("list");
   var newOption = document.createElement("option");

   newOption.text = document.getElementById("txtbox").value;
   select.add(newOption);
}

4.Try-it-out - Generate random characters


Welcome to To generate Random Character id
File Name - index.js

function stringGen()
{
   var text = "";
   var val = document.querySelector("#num").value;
   var possible =
"ABCDEFGHIKLMNOPQRSTVXYZabcdefghijklmnopqrstuvwxyz01234546789"
   for (var i=0;i< val; i++)
   text += possible.charAt(Math.floor(Math.random() * possible.length));
   return text;
}
5.Try-it-out - Simple Calculator
Welcome to To create a simple calculator
File Name - index.js

function update(value) {
    //Type the code here.
    document.getElementById('screen').value += value;
}

function result() {
    //Type the code here.
    document.getElementById('screen').value =
eval(document.getElementById('screen').value);
}

function form_reset() {
    //Type the code here.
   document.getElementById('screen').value = "";
}

You might also like