Question

In: Computer Science

/* 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 to the console



// 2) Create an array named foods and put your 5 favorite foods
// in the array as items.
// 5 fav foods = sushi, ramen, korean bbq, pizza, wings
// Create a for / in loop that will loop through the items in the foods array
// Print a favorite food item to the console each time the loop executes
// When finished, you should have printed each favorite food item to the console



// 3) Create a variable x and set it equal to 50.
// Create a while loop that executes while x is greater than zero.
// Print the value of x to the console every time the loop executes.
// Decrement the value of x by one every time the loop executes.
// Your loop should count backwards from 50 to 1 and print each number in the
// console.



// 4) Create a variable named myNum and set it equal to 10.
// Create a while loop that executes while myNum is less than 5.
// In the loop, print the value of myNum to the console.
// Below that loop, create a do / while loop.
// Set the while condition the same as first while loop.
// Print the value of myNum to the console in the loop.
// Comment below your loops to explain the outcome. /* multi-line comment */



// 5) Create a variable named x and set it equal to zero.
// Create a while loop that executes while x is less than ten.
// In the code block of the loop, set x equal to a random number between
// one and ten using the previous random number formula we learned with
// the Math object.
// After assigning x the random number, print the value of x to the console.
// The loop should continue to execute until the value of x equals 10.

Solutions

Expert Solution

/* 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 to the console
var i = 0;
while (i < 10) {
    console.log(i);
    i++;
}

// 2) Create an array named foods and put your 5 favorite foods
// in the array as items.
// 5 fav foods = sushi, ramen, korean bbq, pizza, wings
// Create a for / in loop that will loop through the items in the foods array
// Print a favorite food item to the console each time the loop executes
// When finished, you should have printed each favorite food item to the console
var foods = ['sushi', 'ramen', 'korean bbq', 'pizza', 'wings'];
for (var food in foods) {
    console.log(food);
}

// 3) Create a variable x and set it equal to 50.
// Create a while loop that executes while x is greater than zero.
// Print the value of x to the console every time the loop executes.
// Decrement the value of x by one every time the loop executes.
// Your loop should count backwards from 50 to 1 and print each number in the
// console.
var x = 50;
while (x > 0) {
    console.log(x);
    c--;
}

// 4) Create a variable named myNum and set it equal to 10.
// Create a while loop that executes while myNum is less than 5.
// In the loop, print the value of myNum to the console.
// Below that loop, create a do / while loop.
// Set the while condition the same as first while loop.
// Print the value of myNum to the console in the loop.
// Comment below your loops to explain the outcome. /* multi-line comment */
var myNum = 10;
while (myNum < 5) {
    console.log(myNum);
}
do {
    console.log(myNum);
} while (myNum < 5);
/*
This while code does not execute.
but the do-while loop execute once, because the condition check was done after it goes once through the loop.
 */

// 5) Create a variable named x and set it equal to zero.
// Create a while loop that executes while x is less than ten.
// In the code block of the loop, set x equal to a random number between
// one and ten using the previous random number formula we learned with
// the Math object.
// After assigning x the random number, print the value of x to the console.
// The loop should continue to execute until the value of x equals 10.
var x = 0;
while (x < 10) {
    x = Math.floor(Math.random() * 11);
    console.log(x);
}

Related Solutions

/* 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 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...
/* 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...
JAVASCRIPT: /* Assignment 03: Complete this javascript */ // 1) Declare a variable named myValue //...
JAVASCRIPT: /* Assignment 03: Complete this javascript */ // 1) Declare a variable named myValue // Assign myValue the value of "Hello, how's it going?" // Print the value of myValue to the console // 2) Use the charAt() method to display the letter t // from the variable myValue in the console // 3) Use the indexOf() method to display the position of "going" // from the variable myValue in the console // 4) Use the slice() method to...
Please follow these instructions to complete this assignment: 1. For this assignment, you are to develop...
Please follow these instructions to complete this assignment: 1. For this assignment, you are to develop 10 questions that you would ask a management official responsible for the financial planning for the organization you have chosen to research for the week 3 paper. 2. Make sure the questions will give you insight into what the company looks for when preparing their yearly budget, fiscal planning strategies, as well as how they monitor their financial condition throughout the year and make...
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: //...
In this assignment, you shall create a complete C++ program that will read from a file,...
In this assignment, you shall create a complete C++ program that will read from a file, "studentInfo.txt", the user ID for a student (first letter of their first name connected to their last name Next it will need to read three integer values that will represent the 3 exam scores the student got for the semester. Once the values are read and stored in descriptive variables it will then need to calculate a weighted course average for that student. Below...
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...
use VISUAL STUDIO CODE to write this javascript program Exercise 1 (a) Create a HTML file...
use VISUAL STUDIO CODE to write this javascript program Exercise 1 (a) Create a HTML file that uses createElement and appendChild to dynamically insert three paragraphs when a button is clicked. (b) Create a HTML file that includes JavaScript that is similar to: let recs = [“my item …1”,”my item…2”, …] i.e. an array that contains several CSV item records. When the user clicks a button, each array element will be rendered as a list element. Use a HTML list....
For this assignment you need to create a ToDo list using Javascript, along with HTML and...
For this assignment you need to create a ToDo list using Javascript, along with HTML and CSS. Begin by creating a HTML page called todo.html. Then create a Javascript file called todo.js and link it in to the HTML page using a script tag. All Javascript for the assignment must be in the separate file. (For CSS, feel free to include styles in a style block at the top of the HTML page, or to link in CSS from a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT