Javascript FizzBuzz Solution
FizzBuzz Challenge Javascript Solution
FizzBuzz Challenge
enter numbers for fizz and buzz=fizz
=buzz
Source Code
HTML with Javascript
<!DOCTYPE html>
<html>
<head>
<title>FizzBuzz</title>
</head>
<body bgcolor="lightblue">
<h1>FizzBuzz Challenge</h1>
<p>enter numbers for fizz and buzz</p>
<input id="x"></input>=fizz
<input id="y"></input>=buzz<br>
<button onclick="fb()">run</button>
<script>
function fb() {
var a = document.getElementById("x").value;
var b = document.getElementById("y").value;
for(i=1; i<101; i++) {
if (i % a === 0 && i % b === 0){ document.write ("Fizz"+"Buzz<br>"); }
else if(i % a === 0) { document.write("Fizz"+"<br>"); }
else if(i % b === 0) { document.write("Buzz"+"<br>"); }
else { document.write(i+"<br>"); } } }
</script>
</body>
</html>
<html>
<head>
<title>FizzBuzz</title>
</head>
<body bgcolor="lightblue">
<h1>FizzBuzz Challenge</h1>
<p>enter numbers for fizz and buzz</p>
<input id="x"></input>=fizz
<input id="y"></input>=buzz<br>
<button onclick="fb()">run</button>
<script>
function fb() {
var a = document.getElementById("x").value;
var b = document.getElementById("y").value;
for(i=1; i<101; i++) {
if (i % a === 0 && i % b === 0){ document.write ("Fizz"+"Buzz<br>"); }
else if(i % a === 0) { document.write("Fizz"+"<br>"); }
else if(i % b === 0) { document.write("Buzz"+"<br>"); }
else { document.write(i+"<br>"); } } }
</script>
</body>
</html>
Click here to run this code on Sololearn
Click here to view FizzBuzz Challenge
I hope you enjoyed this content please consider supporting the development of Free Code Examples
Comments
Post a Comment