Question

In: Computer Science

/* Complete this javascript file according to the individual instructions given in the comments. */ //...

/* 
Complete this javascript file according to the individual instructions
given in the comments. */

// 1) Declare an array named myArray
// Assign myArray three elements: 'Tuesday',3,true
// Print myArray to the console with console.log()


// 2) Use typeof on each element in myArray
// Example: typeof myArray[0];
// Print all 3 lines to the console with console.log()



// 3) Declare a variable named myStart and set it to
// the value of the length property applied of myArray
// Print the result to the console with console.log()



// 4) Use the .splice() method on myArray
// Use your variable myStart - 2 as the first parameter of .splice()
// Use 0 as the second parameter
// In the third parameter, specify 'hamburgers' as the element to add
// Print the resulting array to the console with console.log()



// 5) Declare an array named myPal
// Give myPal these 4 elements: 'taco','cat','race','car'
// Set a string equal the first element + the second element
// Print the string to the console with console.log()



// 6) Use the .concat() method to merge myArray and myPal
// Print the result to the console with console.log()



// 7) Use the .join() method on myPal and specify no connector parameter
// Print the result to the console with console.log()


// 8) Use .sort() on myArray
// Print the resulting array to the console with console.log()


// 9) Use .slice() on myPal and specify that it begins at
// myPal.length - 2
// Print the result to the console



// 10) **Solving a problem!
// Declare a string named revOrder that is equal to 'Taco cat'
// Utilize indexOf(), split(), splice(), reverse(), and join() to
// 1) turn the string into an array
// 2) locate and remove the empty space
// 3) Reverse the order of the array
// 4) Turn the array back into a string
// 5) Log each step to the console.
// Can you combine any of the steps into one statement?
// You should finish with a result of "tacocaT"

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new web page with name "jsArrayDemo.html" is created, which contains following code.

jsArrayDemo.html :

<!DOCTYPE html>

<html lang="en">

<head>

<!-- title for web page -->

<title>javascript Array</title>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

</head>

<body>

<!-- <script> is used for javascript -->

<script>

// 1) Declare an array named myArray

// Assign myArray three elements: 'Tuesday',3,true

// Print myArray to the console with console.log()

var myArray=['Tuesday',3,true];

//using for loop ,print each array element

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

console.log("myArray["+i+"] : "+myArray[i]);

}

// 2) Use typeof on each element in myArray

// Example: typeof myArray[0];

// Print all 3 lines to the console with console.log()

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

console.log("typeof(myArray["+i+"]) : "+typeof(myArray[i]));

}

// 3) Declare a variable named myStart and set it to

// the value of the length property applied of myArray

// Print the result to the console with console.log()

var myStart=myArray.length;

console.log("myArray length : "+myStart);

// 4) Use the .splice() method on myArray

// Use your variable myStart - 2 as the first parameter of .splice()

// Use 0 as the second parameter

// In the third parameter, specify 'hamburgers' as the element to add

// Print the resulting array to the console with console.log()

myArray.splice(myStart - 2 ,0,"hamburgers");

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

console.log("myArray["+i+"] : "+myArray[i]);

}

// 5) Declare an array named myPal

// Give myPal these 4 elements: 'taco','cat','race','car'

// Set a string equal the first element + the second element

// Print the string to the console with console.log()

var myPal=['taco','cat','race','car'];

console.log(myPal[0]+myPal[1]);

// 6) Use the .concat() method to merge myArray and myPal

// Print the result to the console with console.log()

myArray=myArray.concat(myPal);

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

console.log("myArray["+i+"] : "+myArray[i]);

}

// 7) Use the .join() method on myPal and specify no connector parameter

// Print the result to the console with console.log()

console.log(myPal.join());

// 8) Use .sort() on myArray

// Print the resulting array to the console with console.log()

myArray.sort();

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

console.log("myArray["+i+"] : "+myArray[i]);

}

// 9) Use .slice() on myPal and specify that it begins at

// myPal.length - 2

// Print the result to the console

console.log(myPal.slice(myPal.length - 2));

// 10) **Solving a problem!

// Declare a string named revOrder that is equal to 'Taco cat'

// Utilize indexOf(), split(), splice(), reverse(), and join() to

// 1) turn the string into an array

// 2) locate and remove the empty space

// 3) Reverse the order of the array

// 4) Turn the array back into a string

// 5) Log each step to the console.

// Can you combine any of the steps into one statement?

// You should finish with a result of "tacocaT"

var revOrder="Taco cat";

var revOrderArray=revOrder.split(" "); //reversing array

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

console.log("revOrderArray["+i+"] : "+revOrderArray[i]);

}

var removeIndex=revOrder.indexOf(" ");

console.log(removeIndex);

//array reverse

var arrayReverse=revOrderArray.reverse();

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

console.log("revOrderArray["+i+"] : "+revOrderArray[i]);

}

//array join

var arrayJoin=arrayReverse.join(" ");

console.log("String is : "+arrayJoin);

</script>

</body>

</html>

======================================================

Output : Open web page jsArrayDemo.html in the browser and will get the screen as shown below

Screen 1 :jsArrayDemo.html

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

/* Assignment : Complete this javascript file according to the individual instructions given in the comments....
/* Assignment : Complete this javascript file according to the individual instructions given in the comments. */ // 1) Utilize comments to prevent the following line from executing alert('Danger!'); // 2) Assign a value of 5 to a variable named x // and print the value of x to the console // 3) Assign a value of 10 to a variable named myNum // and print the value of myNum to the console // 4) Assign the product of x...
/* Assignment: Complete this javascript file according to instructions given in the comments. */ // 1)...
/* Assignment: Complete this javascript file according to instructions given in the comments. */ // 1) Declare a variable named myName equal to your first name //Firstname is Susan // Construct a basic IF statement that prints the variable to the // console IF the length of myName is greater than 1 // 2) Copy your IF statement from above and paste it below // Change the IF statement to check if the length of myName // is greater than...
/* Assignment : Complete this javascript file according instructions in comments. */ // 1) Create a...
/* Assignment : Complete this javascript file according instructions in comments. */ // 1) Create a for loop that loops through its code block 10 times // In the first statement, set the variable i equal to zero // In the second statement, tell the loop to execute while i is less than ten // In the third statement, increment i by one each time the loop executes // In the code block of the loop, print the variable i...
Please complete the following code in C using the comments as instructions. Further instructions are below...
Please complete the following code in C using the comments as instructions. Further instructions are below the code. challenge.c // goal: print the environment variables to the file "env.txt", one per line // (If envp is NULL, the file should be empty, opening in write mode will do that.) // example: // inputs: // envp/environ = {"E1=2","E2=7",NULL} // outputs: // env.txt as a string would be "E1=2\nE2=7\n" // example: // inputs: // envp/environ = {NULL} or NULL // outputs: //...
I need to complete this C++ program. The instructions are in the comments inside the code...
I need to complete this C++ program. The instructions are in the comments inside the code below: ------------------------------------------------------------------------- Original string is: this is a secret! Encypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! //Encoding program //Pre-_____? //other necessary stuff here int main() { //create a string to encrypt using a char array cout<< "Original string is: "<<string<<endl; encrypt(string); cout<< "Encrypted string is: "<<string<<endl; decrypt(string); cout<<"Decrypted string is: "<<string<<endl; return 0; } void encrypt(char e[]) { //Write implementation...
Task 8.2 - Individual report. * Instructions: According to the instructions in module one, present an...
Task 8.2 - Individual report. * Instructions: According to the instructions in module one, present an individual report on the assigned topic (choose one of the 10 presented). The report will include aspects such as: definition of the topic, Historical background, advantages and disadvantages and your arguments on the contribution that you consider most significant and impactful for business administration. Present examples of corporations currently applying this method successfully. The report must be written using the essay type writing format...
(Javascript) Modify the JavaScript file to implement a function named calculateTotalPrice. At the bottom of the...
(Javascript) Modify the JavaScript file to implement a function named calculateTotalPrice. At the bottom of the file are sample inputs and outputs to test your implementation. /* * The price per ticket depends on the number of tickets * purchased, there are 4 ticket pricing tiers. Given the * number of tickets return the total price, formatted to * exactly two decimal places with a leading dollar sign. * Tier 1: *   Minimum number of tickets: 1 *   Price per...
This needs to be written in JavaScript with two files. One HTML file and a JavaScript...
This needs to be written in JavaScript with two files. One HTML file and a JavaScript file. Make an empty HTML file, put three buttons inside the body and an empty main tag below the buttons. The text of the buttons should be "Foo", "Bar", and "FooBar" respectively. Don't put the " in the buttons that's just for clarification in these instructions. Add unique IDs to each button In your JavaScript, get 3 separate references to the buttons using the...
First create the text file given below. Then complete the main that is given. There are...
First create the text file given below. Then complete the main that is given. There are comments to help you. An output is also given Create this text file: data1.txt -59 -33 34 0 69 24 -22 58 62 -36 5 45 -19 -73 62 -5 95 42 ` Create a project and a Main class and copy the Main class and method given below. First declare the array below the comments that tell you to declare it. Then there...
According to the Internal Revenue Service, the average length of time for an individual to complete...
According to the Internal Revenue Service, the average length of time for an individual to complete (keep records for, learn, prepare, copy, assemble, and send) IRS Form 1040 is 10.41 hours (without any attached schedules). The distribution is unknown. Let us assume that the standard deviation is two hours. Suppose we randomly sample 36 taxpayers. A) In words, define the random variable X. the length of time, in minutes, for an individual to complete IRS Form 1040the length of time,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT