Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Assignment 0 files #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<div class="container">

<h1>Hello World!</h1>
<p class="lead">This is something!</p>
<p class="lead">Waiting for fizzbuzz to run ...</p>

</div><!-- /.container -->

Expand All @@ -36,5 +36,6 @@ <h1>Hello World!</h1>
<!-- 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 src="js/app.js"></script>
</body>
</html>
68 changes: 68 additions & 0 deletions js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*

Assignment 0
CSCI E-32

September 8, 2015

Michael Shull
[email protected]

This code provides a function which accepts a number
and loops until that number is reached while collecting
an array of strings determined by each iteration of
the number loop. If the iteration is a multiple of both
5 and 3 the string 'FizzBuzz' is added to the array. If
the iteration is just a multiple of 3 then the string
'Fizz' is added to the array. If the iteration is just
a multiple of 5 then the string 'Buzz' is added to the
array. If the iteration is not a multiple of 3 or 5 then
just the iteration numerical value is added to the array.
When the loop is complete the final array is returned.

The bottom portion of this code uses jQuery to determin
when the document is done loading and then runs code that
calls the fizzbuzz function and passes it the number 30. The
returned array is then looped through to create an HTML string
which is used to replace the content within the only paragraph
tag in the body on the index.html page.

*/

function fizzbuzz(amount) {
var arr = [];
for (var i=1; i<=amount; i++) {
if (i % 5 == 0 && i % 3 == 0) {
arr.push('FizzBuzz');
} else if (i % 3 == 0) {
arr.push('Fizz');
} else if (i % 5 == 0) {
arr.push('Buzz');
} else {
arr.push(i);
}
}
return arr;
}

// Shorthand for document.ready
// Wait for document to finish loading

$(function() {

// get array and create placeholder string variable
var arr = fizzbuzz(30);
var str = '';

// loop through string array
for (var i=0; i<arr.length; i++) {
// write to console for fun
console.log(arr[i]);
// append to string variable
str += '<li>' + arr[i] + '</li>';
}

// replace paragraph content in index.html
$('p.lead').html('<ol>'+str+'</ol>');

});