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();
Download
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.
Hello! Python by Anthony Briggs(9383)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9352)
The Mikado Method by Ola Ellnestam Daniel Brolund(9321)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7858)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7411)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7348)
Grails in Action by Glen Smith Peter Ledbrook(7303)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7124)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(5968)
Kotlin in Action by Dmitry Jemerov(4653)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(3912)
Functional Programming in JavaScript by Mantyla Dan(3726)
Learning Java by Patrick Niemeyer & Daniel Leuck(2872)
Mastering Python for Finance by Weiming James Ma;(2852)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(2844)
Windows APT Warfare by Sheng-Hao Ma(2755)
WordPress Plugin Development Cookbook by Yannick Lefebvre(2625)
Mastering Java 9 by Dr. Edward Lavieri(2576)
Architecting Modern Java EE Applications: Designing lightweight, business-oriented enterprise applications in the age of cloud, containers, and Java EE 8 by Daschner Sebastian(2564)