JavaScript — The basics

Guide 04 / 4

Resources and review

Learn to consult documentation, solve an error and check what you have learned.

Expected outcome :

Find reliable information and explain what you have built.

Reading
0%

01 · Consulting the references

The resources are linked at the bottom of the guide.

MDN · JavaScript Guide

Read the chapters on variables, functions and flow control. Redo the small examples with a recipe duration rather than an abstract number.

Mission : écrire estRapide(20) puis estRapide(45).

MDN · querySelectorAll and events

Check the result type of querySelectorAll and the addEventListener examples. Find these uses again in app.js.

Mission : compter les cartes sélectionnées avec cartes.length.

MDN · localStorage

Explore the difference between setItem, getItem and removeItem. Check which origin the storage belongs to.

Mission : expliquer pourquoi changer de port peut changer les données accessibles.

02 · Troubleshooting and preparing for PHP

Read the console's first error first.

Cannot read properties of null

A selector does not find the expected element, or the script runs before it is created. Check the HTML ids, the selector spelling and defer.

document.querySelector("#recherche") doit renvoyer un élément, pas null.

The filter or the counter seems wrong

Check data-titre, data-duree and Number. Check that visibles goes back to 0 on each call. If a card marked hidden stays visible, check the [hidden] CSS rule.

Données de référence : soupe 20, salade 10, tarte 45.

Self-assessment and browser limits

Explain a function, an event, a conversion and a combined condition. Pass the workshop's six scenarios. These filters act on the cards already loaded, without saving any recipe on a server.

Je sais :
□ lire un champ ;
□ parcourir les cartes ;
□ combiner deux critères ;
□ afficher un compteur avec textContent ;
□ trouver une erreur dans la console.
Remember :

Next: PHP will produce the pages on the server side; MySQL and PDO will then provide shared persistence.