forked from CSCI-E32/fizzbuzz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
97 lines (84 loc) · 2.67 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<title>Assignment 0</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="js/jquery-2.1.4.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
function printOutput() {
var limit = document.getElementById('input').value;
var result = "";
if(isNaN(limit)==false && limit>=1){
for (var x = 1; x <= limit; x++){
if(( x%3 == 0 ) && ( x%5 == 0)){
if(x==limit){
result += 'FizzBuzz';
}else{
result += 'FizzBuzz, ';
}
continue;
}
else if(x%5 == 0){
if(x==limit){
result += 'Buzz';
}else{
result += 'Buzz, ';
}
continue;
}
else if( ( x%3 == 0 ) ){
if(x==limit){
result += 'Fizz';
}else{
result += 'Fizz, ';
}
continue;
}else{
if(x==limit){
result += x;
}else{
result += x + ', ';
}
}
}
console.log(result);
document.forms['myForm']['output'].value =result;
}else{
console.log("Enter a valid positive integer greater than or equal to 1");
document.forms['myForm']['output'].value ="Enter a valid positive integer greater than or equal to 1";
}
}
</script>
<body>
<div class="container">
<p class="lead">Enter a number ( say N ) to print numbers from 1 to N. And print 'Fizz' for multiples of 3 and 'Buzz' for multiples of 5 and 'FizzBuzz' for multiples of 3 and 5 </p>
<form class="form-horizontal" role="form" id="myForm">
<label for="inputType" class="col-sm-2 control-label">Enter Limit</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="input" placeholder="Input number"></input>
<br/><br/><br/>
<button type="button" class="btn btn-primary btn-lg" onclick="printOutput()">Submit</button>
<br/><br/>
<textarea class="form-control" id="output"></textarea>
</div>
</form>
</div><!-- /.container -->
</body>
</html>