JavaScript: QuickStart Guide - The Simplified Beginner's Guide To JavaScript (JavaScript, JavaScript Programming, JavaScript and Jquery) by ClydeBank Technology & Martin Mihajlov


JavaScript: QuickStart Guide - The Simplified Beginner's Guide To JavaScript (JavaScript, JavaScript Programming, JavaScript and Jquery) by ClydeBank Technology & Martin Mihajlov

Author:ClydeBank Technology & Martin Mihajlov [Technology, ClydeBank]
Language: eng
Format: epub
Publisher: ClydeBank Media LLC
Published: 2015-06-16T18:30:00+00:00


Image 16. Implementing a function to check the users’ age

Additionally, we can use what we learned in previous chapters and make this function more intelligent. Instead of just receiving the answer "Please come back in a few years.",we can calculate the actual difference between 18 and the age entered by the user. To do this we will first introduce a variable nameddifferencein the function, than calculate that difference as18-ageif the entered value for age is less than 18, and finally print thedifference variable along with the text.

function checkAge() {

var difference;

if (age >= 18) {

document.write("You have reached the age of wisdom, please enter and have some fun.");

}

else {

difference = 18 - age;

document.write("Please come back in "+difference+" years.");

}

}

var age = prompt("How old are you?","");

checkAge();



Loading...
Download

JavaScript: QuickStart Guide - The Simplified Beginner's Guide To JavaScript (JavaScript, JavaScript Programming, JavaScript and Jquery) by ClydeBank Technology & Martin Mihajlov.epub



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.