Tutoriales de Informática y Dispositivos Móviles
Tutoriales de Informática y Dispositivos Móviles
JavaScript exercises

JavaScript exercises Part 1

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");
}

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.

Translate »