Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 3.1 Write a server script function that receives the number of digits n

ID: 3724922 • Letter: Q

Question

Question 3.1 Write a server script function that receives the number of digits needed for a sequence of prime numbers starting from 61. Replace any prime number with capital letter by using ASCII values from 65 to 90 (A to Z). At the end, the function should return a series of prime numbers and letters (if any). (10 marks) Question 3.2 Assume a string input with the format of "(word1, word2, word3); (word4, word5, word6), ..; (wordN, wordN+1, wordN+2)" have been read in from a text file. Write a server script that determine the longest word among the 3 words and its average letters in a set. Highlight longest word in every set of words with purple bolded text and display all averages in 2 decimal places at last. Test your script with the following input: "(kiwi, banana, tomatoes); (a, are, am); (I, you, we); (he, has, hardworking); (generous, she, just)." The desired output will be: (kiwi, banana, tomatoes); (a, are, am); (0, you, we): (he, has, hardworking): (generous, she, just) Set 1: 6 Set 2: 2 Set 3: 2 Set 4: 5.33 Set 5:5 15 marks

Explanation / Answer

CODE:

3.1

// check if number is prime.

function checkprimenumber(n){

for (c=2; c<=n - 1; c++){

if ( n%c == 0 ){

return false;

}

return true;

}

}

// returns a list of numbers and ASCII equivalent of prime numbers

function retList(){

var resArray = []

for (i=65; i<=90; i++){

var res = i;

if(checkprimenumber(i) == true)

res = String.fromCharCode(i);

resArray.push(res)

}

}

----------------------------------------------------

3.2

Content of file is not properly provided.

How will each line of the file will be -

"kiwi,banana,tomatoes" OR "(kiwi,banana,tomatoes)" ?

So, I am just providing the code for the case to find longest word in sentence like "kiwi banana tomatoes"

var sentence = "Hello my name is Jamie."

function longestWord(sentence) {

var words = sentence.split(' ');

var longestWord = "";

var longestLength = 0;

for (var i = 0; i < words.length; i++) {

if (longestLength < words[i].length) {

longestWord = words[i];

longestLength = words[i].length;

} else {  

continue;

}

}

return longestWord;

}

longestWord("kiwi banana tomatoes");

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote