Skip to content
Permalink
bdb27be23d
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 77 lines (64 sloc) 2.34 KB
/**
*
* 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.
*
**/
var logVar = document.querySelector("#log");
function fancyLog(text) {
console.log(text);
logVar.innerHTML +="<p>"+text+"</p>"
// Now what goes in here?
}
<!-- fancyLog("test"); -->
/**
*
* 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*0.621371;
console.log(miles);
console.log(kilo);
return miles;
}
console.log(kilometersToMiles(10));
/**
* 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 day = new Date();
var currentyear = day.getFullYear();
var birthyear = prompt("What is your birthyear");
calculateAges(currentyear,birthyear);
/**
* 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 distance = kilometersToMiles(5);
console.log(distance);
fancyLog("5 kilometers is equal to " + distance + " miles.");
console.log(distance);