Question

3. Write a JavaScript code that print 3 color (yellow, black, red). You should create an...

3. Write a JavaScript code that print 3 color (yellow, black, red). You should create an array that has all the color then use a loop to print the array.

Homework Answers

Answer #1

Required program in Javascript -->

<!DOCTYPE html>
<html>
<body>
<script>
var colors = ["yellow","black","red"]; //colors are stored in array colors
for(var i=0;i<3;i++){ // for loop starts from index 0 to index 2 (since there are only 3 elements)
document.write(colors[i]+" "); // this will print the element of an array with a space
}
</script>
</body>
</html>

Program first defines an array and give colors to the array. Then for loop will start from index 0 to index 2 and will print colors[i] and a space each time for loop is executed.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
5 -​Create a web page that contains JavaScript code as discussed in class. ​Your page should...
5 -​Create a web page that contains JavaScript code as discussed in class. ​Your page should use the defaults for color, font face and font size. ​Count the numbers from 1 to 50. Skip 1 blank space between each value. You must use a ​for() loop
You have been given the following lists of Color and their specific codes: Colors = ['Red','Blue','Green','Black','Yellow',‘Orange’,‘Purple’,‘Nocolor’]...
You have been given the following lists of Color and their specific codes: Colors = ['Red','Blue','Green','Black','Yellow',‘Orange’,‘Purple’,‘Nocolor’] Codes = [97,17,19,128,66,111,231,00] 1. Using codeDict, find the score for 'Nocolor'. 2. Add a code of 333 for 'Nocolor'. 3. Create a sorted list of all the codes in codeDict. 4. Update the name for 'Nocolor' to be ‘white’ 5. White was not a part of original colors list so, just Delete it and its code from codeDict. USE PYTHON CONSOLE AND SUBMIT THE...
Use visual studio code to write the javascript programme. Write a function that counts the number...
Use visual studio code to write the javascript programme. Write a function that counts the number of values each item attribute has. This is effectively a group-by on the item table for each column. For example: if the first attribute is colour, and its values are [ ‘red’, ‘black’, ‘white’, ‘black’, ‘red’ ], the counts for colour would be: red 2 black 2 white 1
Write the below code to use HTML and JavaScript. 1)Write a JavaScript program to create a...
Write the below code to use HTML and JavaScript. 1)Write a JavaScript program to create a new string from a given string changing the position of first and last characters. The string length must be greater than or equal to 1. 2)Write a JavaScript program to check whether a string starts with 'Java' and false otherwise
The Color Mixer The colors red, blue, and yellow are known as the primary colors because...
The Color Mixer The colors red, blue, and yellow are known as the primary colors because they cannot be made by mixing other colors. When you mix two primary colors, you get a secondary color, as shown down below. Once you have complete that task, use a repetition structure down below. When you mix red and blue, you get purple. When you mix red and yellow, you get orange. When you mix blue and yellow, you get green. Using While...
write a loop to print an array a with pointers backwards. You can use a variable...
write a loop to print an array a with pointers backwards. You can use a variable “size” for array size. write you code in C
C# code required Write two code segments that print the integers 1 through 10. One segment...
C# code required Write two code segments that print the integers 1 through 10. One segment should use a while loop and the other should use a for loop.
For this lab assignment you will need to write some code and create some graphs. You...
For this lab assignment you will need to write some code and create some graphs. You may use excel to create your graphs, or other language of your choice. Your data needs to demonstrate the experimental running time for Selection Sort (code in book), Merge Sort (code in book), and the Arrays.sort() method. Here is a basic outline of how you need to code this assignment. 1) Create several arrays of size 100, 1000, 10000, 100000, 1000000, … (you need...
Write a flatten function in JavaScript that uses recursion to create an array containing all nested...
Write a flatten function in JavaScript that uses recursion to create an array containing all nested arrays in a single array. The function should pass the test: it("longer list, no mutation, completely flat", function () { var data = [[[1],2,[3]],4,[5,6]]; var orig_data = data; expect(ms.flatten(data)).toEqual([1,2,3,4,5,6]); expect(data).toEqual(orig_data); });
Sample A Reagent Used Color Recorded Lugol's (IKI) Dark Brown/Black Benedict's Orange-Red Biuret's Violet Sudan IV...
Sample A Reagent Used Color Recorded Lugol's (IKI) Dark Brown/Black Benedict's Orange-Red Biuret's Violet Sudan IV Red Layer Sample B Reagent Used Color Recorded Lugol's (IKI) Dark Brown/Black Benedict's Yellow-Orange Biuret's Violet Sudan IV Red Layer Sample C Reagent Used Color Recorded Lugol's (IKI) Yellow Benedict's Orange-Red Biuret's Violet Sudan IV Very little color mixed throughout Sample D Reagent Used Color Recorded Lugol's (IKI) Dark Brown/Black Benedict's Blue Biuret's Violet Sudan IV Red Layer Sample E Reagent Used Color Recorded...