Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
function and scope assignment
  • Loading branch information
crl13003 committed Feb 4, 2016
1 parent afccfec commit 0d7d70b
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 0 deletions.
44 changes: 44 additions & 0 deletions index.html
@@ -0,0 +1,44 @@
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="apple-touch-icon" href="apple-touch-icon.png">
<!-- Place favicon.ico in the root directory -->

<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<script src="js/vendor/modernizr-2.8.3.min.js"></script>
</head>
<body>
<!--[if lt IE 8]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->

<div id="log">
<h2>The Log</h2>
<p id="lede">
There should be a new paragraph for every javascript line you write to the console. See Instructions in the "Javascript" window. WRITE YOUR CODE BELOW THE COMMENT BLOCKS FOR READABILITY. <strong>This paragraph should remain!</strong>
</p>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.3.min.js"><\/script>')</script>
<script src="js/plugins.js"></script>
<script src="js/main.js"></script>

<!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
<script>
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
e.src='https://www.google-analytics.com/analytics.js';
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
ga('create','UA-XXXXX-X','auto');ga('send','pageview');
</script>
</body>
</html>
69 changes: 69 additions & 0 deletions js/main.js
@@ -0,0 +1,69 @@
/**
*
* Write a function that will simultaneously perform a console.log()
* and write a new paragraph to the #log div with whatever text you give it.
* You are just creating the function, NOT calling it yet. Here, I'll get you started.
*
**/

function fancyLog(text) {
console.log(text);
// Now what goes in here?
var log = document.querySelector("#log");
log.innerHTML += ("<p>" + text + "</p>");
}

/**
*
* Write a function that will automatically calcuate the two ages based on a birth
* year and a given year. DO NOT CALL THE FUNCTION YET. The function should use your fancyLog()
* function above. I'll get you started here, too.
*
*/

function calculateAges(currentyear,birthyear) {
var age1 = currentyear-birthyear;
// Calculate age2 properly.
var age2 = age1 - 1;
// Now call fancyLog() with the text "If you were born in {birthYear}, your age could be {age1} or {age1}."
fancyLog("If you were born in " + birthyear + " your age could be " + age1 + " or " + age2 + ".")
}

/**
* Now, write a function that will convert a value (kilometers) to miles.
* Your function should RETURN the value in miles.
* DO NOT CALL THE FUNCTION YET
* I'll get you started.
*/

function kilometersToMiles(kilo){

// Do the converstion here and set a variable "miles"
var miles = kilo * .621;

return miles;
}

/**
* Now, we're going to call our functions!
* Write a call to fancyLog() and log/display "Let's get started with functions!"
*/
fancyLog("Let's get started with functions!")
/**
* Use javascript prompt(); to ask the user for their birth year.
* Use the results from that prompt() to call "calculateAges()"
* FOR 5 BONUS POINTS, use javascript to dynamically get the
* current year instead of hand-coding it
* Your calculateAges() function should automatically fancyLog();
*/
var promptResults = prompt("Put in your birth year");
var thisYear = 2016;
calculateAges(thisYear, promptResults);


/**
* Call your kilometersToMiles() function to convert 5K to miles. Store the returned value in a
* variable here. Use fancyLog() to display/log "5 kilometers is equal to {miles} miles."
*/
var storeKilos = kilometersToMiles(5);
fancyLog("5 kilometers is equal to " + storeKilos + " miles.")
24 changes: 24 additions & 0 deletions js/plugins.js
@@ -0,0 +1,24 @@
// Avoid `console` errors in browsers that lack a console.
(function() {
var method;
var noop = function () {};
var methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn'
];
var length = methods.length;
var console = (window.console = window.console || {});

while (length--) {
method = methods[length];

// Only stub undefined methods.
if (!console[method]) {
console[method] = noop;
}
}
}());

// Place any jQuery/helper plugins in here.
6 changes: 6 additions & 0 deletions js/vendor/jquery-1.11.3.min.js

Large diffs are not rendered by default.

0 comments on commit 0d7d70b

Please sign in to comment.