Question

In: Computer Science

JavaScript 1. FizzBuzz Submit js file with functioning code Write a program that uses console.log to...

JavaScript

1. FizzBuzz Submit js file with functioning code Write a program that uses console.log to print all the numbers from 1 to 120, with two exceptions. For numbers divisible by 4, print "Fizz" instead of the number, and for numbers divisible by 10 (and not 4), print "Buzz" instead. When you have that working, modify your program to print "FizzBuzz", for numbers that are divisible by both 4 and 10 (and still print "Fizz" or "Buzz" for numbers divisible by only one of those).

Tip: numbers is clearly a looping job remainder (%) operator for checking whether a number is divisible by another number (has a remainder of zero) there are three possible outcomes for every number, so you’ll have to create an if/else if/else chain.

Solutions

Expert Solution

JavaScript wrote as below:

<h3>Program to print 1-120 number </h3>
<script>

for(var i = 1; i < =120; i += 1) {
if(((i%4)==0) &&((i%10)!=0)){
   console.log("\nFizz");
   //document.write("\nFizz");
}else if(((i%4)!=0) &&((i%10)==0)){
   console.log("\nBuzz");
   //document.write("\nBuzz");   
}else if(((i%4)==0) &&((i%10)==0)){
   console.log("\nFizzBuzz");
   //document.write("\nFizzBuzz");
}else{
   console.log("\n"+i);
   //document.write("\n"+i);
}
}
</script>

Output:

Program to print 1-120 number

1 2 3 Fizz 5 6 7 Fizz 9 Buzz 11 Fizz 13 14 15 Fizz 17 18 19 FizzBuzz 21 22 23 Fizz 25 26 27 Fizz 29 Buzz 31 Fizz 33 34 35 Fizz 37 38 39 FizzBuzz 41 42 43 Fizz 45 46 47 Fizz 49 Buzz 51 Fizz 53 54 55 Fizz 57 58 59 FizzBuzz 61 62 63 Fizz 65 66 67 Fizz 69 Buzz 71 Fizz 73 74 75 Fizz 77 78 79 FizzBuzz 81 82 83 Fizz 85 86 87 Fizz 89 Buzz 91 Fizz 93 94 95 Fizz 97 98 99 FizzBuzz 101 102 103 Fizz 105 106 107 Fizz 109 Buzz 111 Fizz 113 114 115 Fizz 117 118 119 FizzBuzz


Related Solutions

Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to...
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to display the current day and time. b) Write a JavaScript program to print the contents of the current window.   c) Write a JavaScript program where the program takes a random integer between 1 to 10 d) Write a JavaScript program to calculate multiplication and division of two numbers (input from the user). e)Write a JavaScript program to create a new string from a given...
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....
Using JavaScript You must submit a file, called indentation.js indentation.js: program to indent The following program...
Using JavaScript You must submit a file, called indentation.js indentation.js: program to indent The following program is difficult to follow because of its indentation: print ( "binary"); var n = Math.pow (2, 31) - 1; var bits = 0; while (n> 0) { bits + = n & 1; n >> = 1; } print ("Number of bits at 1:" + bits); for (var i = 1; i <= bits; i ++) { var str = ""; if (i% 3...
Write the programs in JavaScript: Write a program that reads a text file and outputs the...
Write the programs in JavaScript: Write a program that reads a text file and outputs the text file with line numbers at the beginning of each line.
1. Write a Java program and Submit only "one .java file" calledNumbers that calls the...
1. Write a Java program and Submit only "one .java file" called Numbers that calls the following methods and displays the returned value:o Write a method called cubeIt that accepts one integer parameter and returns the value raised to the third power as an integer.2. Write a method called randomInRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive.o Write a method called larger that accepts two double parameters and...
Name your functions countOnesLoop() and countOnesWhere() and submit your code in a file named countOnes.py. Write...
Name your functions countOnesLoop() and countOnesWhere() and submit your code in a file named countOnes.py. Write a function that consists of a set of loops that run through an array and count the number of ones in it. Do the same thing using the where() function (use info(where) to find out how to use it) (in python)
Using the code below from “LStack.h” file, write the code for a main program that takes...
Using the code below from “LStack.h” file, write the code for a main program that takes as input an arithmetic expression. The program outputs whether the expression contains matching grouping symbols. For example, the arithmetic expressions { 25 + ( 3 – 6 ) * 8 } and 7 + 8 * 2 contains matching grouping symbols. However, the expression 5 + { ( 13 + 7 ) / 8 - 2 * 9 does not contain matching grouping symbols....
Name your program file warmup.py Submit your working Python code to your CodePost.io account. In this...
Name your program file warmup.py Submit your working Python code to your CodePost.io account. In this challenge, establish if a given integer num is a Curzon number. If 1 plus 2 elevated to num is exactly divisible by 1 plus 2 multiplied by num, then num is a Curzon number. Given a non-negative integer num, implement a function that returns True if num is a Curzon number, or False otherwise. Examples is_curzon(5) ➞ True 2 ** 5 + 1 =...
Write an Html Page that uses JavaScript Program to make a Blackjack Game. I need to...
Write an Html Page that uses JavaScript Program to make a Blackjack Game. I need to write an html file (P5.html) that uses JavaScript program to create a Blackjack game. 1. Blackjack Games Rules: a. The object of the game is to "beat the dealer", which can be done in a number of ways: • Get 21 points on your first two cards (called a blackjack), without a dealer blackjack; • Reach a final score higher than the dealer without...
Write code that does the following: Opens a file named output.txt, uses a loop to write...
Write code that does the following: Opens a file named output.txt, uses a loop to write the even number from 2 through 100 to the file and then close the file. java based code please.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT