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 javascript file according to the individual instructions given in the comments. */ // 1)...
/* complete javascript file according to the individual instructions given in the comments. */ // 1) Prompt the user to enter their first name. // Display an alert with a personal greeting for the user // with their first name (example: Hello, Dave!) // 2) Create a Try code block that will cause a ReferenceError. // Create a Catch code block that will display the error in the // console with console.error() // 3) Prompt the user to enter a...
/* Complete this javascript file according to the individual instructions given in the comments. */ //1)...
/* Complete this javascript file according to the individual instructions given in the comments. */ //1) Create an Object using an Object Literal (the easiest way) // Name your object Breakfast // Your object should have 3 key:value pairs // The three keys should be: breakfast, lunch, dinner // Put your food choice for each as the value // 2) Display the keys of your Breakfast object in the // console. We have learned two ways to do this.. either...
/* 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...
Complete this javascript question according to the instructions given in the comments. *** DO NOT CHANGE...
Complete this javascript question according to the instructions given in the comments. *** DO NOT CHANGE any of the code that you are not instructed to. */ //////////////////// // Hint: If you see a console.log() in my examples, it is // likely a "return" goes there in your assignment. /////////////////// // 1) Define a "Vehicle" class that has a "wheels" property equal to 4 in // the constructor and a method named "rolling" that returns a string // equal to...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT