Created
December 9, 2017 14:32
-
-
Save imparvez/b928373e517c7111d7225469cddf158d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Fizz Buzz</title> | |
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700" rel="stylesheet"> | |
<link rel="stylesheet" href="style.css"> | |
</head> | |
<body> | |
<div class="wrapper"> | |
<input type="text" id="array"> | |
<button id="button">FizzBuzz</button> | |
<div class="result-wrapper"> | |
</div> | |
</div> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script> | |
<script src='./script.js'></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fizzBuzz(arr){ | |
if(arr.length != 0) { | |
let result = [], | |
p = ""; | |
for(let i = 1; i <= arr; i++) { | |
let sum = ""; | |
if(i % 3 === 0) { sum += "Fizz" }; | |
if(i % 5 === 0) { sum += "Buzz" }; | |
if(sum === '') { | |
result.push(i); | |
} else { | |
result.push(sum); | |
} | |
} | |
renderList(result); | |
} else { | |
$('.result-wrapper').text('Please enter something in the text box'); | |
} | |
} | |
var renderList = function(givenArray){ | |
$('.result-wrapper').empty(); | |
var p = ""; | |
for(index in givenArray){ | |
console.log(givenArray[index]); | |
p += "<p>"+givenArray[index]+"</p>"; | |
} | |
$('.result-wrapper').append(p); | |
} | |
$('#button').click(function(){ | |
var arrayRange = $('#array').val(); | |
fizzBuzz(arrayRange); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:root { | |
font-family: 'Roboto'; | |
} | |
.wrapper { | |
max-width: 600px; | |
width: 100%; | |
margin: 150px auto 0; | |
text-align: center; | |
} | |
#array { | |
width: 50%; | |
height: 64px; | |
margin-bottom: 20px; | |
border-radius: 5px; | |
font-family: 'Oswald', sans-serif; | |
font-size: 18px; | |
cursor: pointer; | |
text-align: center; | |
border: none; | |
border-bottom: 3px solid #dc2430; | |
border-radius: 0; | |
display: inline-block; | |
vertical-align: top; | |
} | |
#array:focus, | |
#array:active { | |
outline: none; | |
} | |
#button { | |
padding: 15px 10px; | |
border: none; | |
border-radius: 3px; | |
background: #7b4397; | |
background: -webkit-linear-gradient(to right, #dc2430, #7b4397); | |
background: linear-gradient(to right, #dc2430, #7b4397); | |
color: #fff; | |
font-weight: bold; | |
cursor: pointer; | |
} | |
.result-wrapper { | |
background: transparent; | |
color: #4e4e4e; | |
line-height: 64px; | |
margin-bottom: 0; | |
display: -webkit-box; | |
display: -ms-flexbox; | |
display: flex; | |
-webkit-box-flex: wrap; | |
-ms-flex: wrap; | |
flex: wrap; | |
-ms-flex-pack: distribute; | |
justify-content: space-around; | |
} | |
.result-wrapper p { | |
float: left; | |
height: 64px; | |
background: #E7E7E7; | |
margin: 0 5px 10px 5px; | |
-webkit-box-flex: 1; | |
-ms-flex: 1 1 25%; | |
flex: 1 1 25%; | |
-webkit-animation: fadeIn 0.4s ease-in-out; | |
animation: fadeIn 0.4s ease-in-out; | |
border-radius: 5px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment