Write, test and debug (if necessary JavaScript for the problems that follow When required to write a function, you must include a script to test the function with at least two different data set In all cases, for testing , you must write an HTML file that refernces the JavaScript file 1- Output : the first 20 fibonacci numbers which are defined as in the sequence 1,1,2,3,…. where each number in the sequence after the second is the sum of the two previous numbers. You must use document. write to produce the output 2- Modify the script of Exercise 1 to use prompt to input a number n that is the number of the Fibonacci number requied as output 3- Input : A line of text, using prompt. Output: The words of the input text, in alphabetical order. 4-Modify the script of Exercise 3 to get a second input from the user which is either “ascending” or “descending” Use this input to determine how to sort the input words 5- Function: reverser Parameter: A number. Return : The number with its digits in reverse order. Purchase the answer to view it

JavaScript Code:

1- To output the first 20 Fibonacci numbers, we can write a function that calculates the Fibonacci sequence and then use document.write to display the numbers.

function fibonacciSequence(n) {
let sequence = [1, 1];
for (let i = 2; i < n; i++) { sequence[i] = sequence[i - 1] + sequence[i - 2]; } return sequence; } let fibonacciNumbers = fibonacciSequence(20); document.write("The first 20 Fibonacci numbers are: " + fibonacciNumbers.join(", ")); ``` 2- To modify the script to use prompt for inputting a number `n`, we can replace the hard-coded value with the value entered by the user using prompt. ```javascript let n = prompt("Enter the number of Fibonacci numbers required:"); let fibonacciNumbers = fibonacciSequence(n); document.write("The first " + n + " Fibonacci numbers are: " + fibonacciNumbers.join(", ")); ``` 3- To input a line of text using prompt and output the words in alphabetical order, we can write a function that splits the input text into words, sorts them alphabetically, and then display the sorted words using document.write. ```javascript let inputText = prompt("Enter a line of text:"); let words = inputText.split(" "); words.sort(); document.write("Words in alphabetical order: " + words.join(", ")); ``` 4- To modify the script to get a second input from the user for sorting order, we can add another prompt to get the input and use it to determine whether to sort the words in ascending or descending order. ```javascript let inputText = prompt("Enter a line of text:"); let words = inputText.split(" "); let sortOrder = prompt("Enter the sort order (ascending or descending):"); if (sortOrder.toLowerCase() === "ascending") { words.sort(); } else if (sortOrder.toLowerCase() === "descending") { words.sort().reverse(); } document.write("Words sorted in " + sortOrder + " order: " + words.join(", ")); ``` 5- To create a function that reverses the digits of a number, we can convert the number to a string, split it into an array of digits, reverse the array, and then join the digits back into a string and convert it back to a number. ```javascript function reverser(number) { let reversedNumber = parseInt(number.toString().split("").reverse().join("")); return reversedNumber; } let number = prompt("Enter a number:"); let reversedNumber = reverser(number); document.write("Reversed number: " + reversedNumber); ``` Please note that the above code may require additional error handling and validation based on the specific requirements and constraints of each exercise.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.

Click Here to Make an Order Click Here to Hire a Writer