JavaScript exercises Part 1
If you are learning JavaScript you need to do these exercises to practise an learn this fantastic language.
To start programming in JavaScript you only need a text editor and a web navigator to do and test the following exercises.
Each exercise needs an html file. The code must be between the labels <body></body>.
Example:
<!DOCTYPE html> <html lang="es"> <head> <title>título</title> <meta charset="utf-8" /> </head> <body> <script> // JavaScript code </script> </body> </html>
Exercise
Ask the age and answer if you can drive
// Ask the age var age = prompt("Write your age"); // Check if the value is a number if (Number(age) == age) { // if it´s older than 18 if (age >= 18) { // Print on screen document.write("You can drive"); } } // If not else { // Show a message alert("Write a valid number"); }