100% found this document useful (2 votes)
971 views5 pages

Examen de Programmation JavaScript

The document provides information about an exam for a JavaScript programming module, including the exam code, subject, duration, and grading. It includes multiple choice questions to test JavaScript fundamentals and code snippets to write functions to find the maximum of an array and change an image source on mouse events. The task is to build a book ordering website by writing JavaScript functions to populate a dropdown with book titles from an array of book data and display book information based on the selection.

Uploaded by

MOHAMED ELHILALI
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
971 views5 pages

Examen de Programmation JavaScript

The document provides information about an exam for a JavaScript programming module, including the exam code, subject, duration, and grading. It includes multiple choice questions to test JavaScript fundamentals and code snippets to write functions to find the maximum of an array and change an image source on mouse events. The task is to build a book ordering website by writing JavaScript functions to populate a dropdown with book titles from an array of book data and display book information based on the selection.

Uploaded by

MOHAMED ELHILALI
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
  • Theory Section
  • Practical Section

Nom : ……………………………………….........................

Prénom : ………………………………………………………….

Direction Régionale RABAT-SALÉ-KENITRA Groupe : ………………………………………………………….

Etablissement : ……………………………………………….
Examen régional de fin de module
Réservé à l’établissement Code :
Année de Formation 2022/2023
……………………………………………………………………….

Code module : M105


Intitulé du module : Programmation JavaScript

Filière DEV Durée : 2h


Année 1A Note finale : / 40
Nom& Prénom du correcteur Émargement

Théorie: (16 Points)


Exercice 1 : QCM (8 points) 1 point par question
Choisir la bonne réponse
1- Quel terme peut-on utiliser pour déclarer une variable en JavaScript ?
a) var
b) let
c) const
d) toutes les réponses précédentes sont correctes
2- Quelle est la méthode servant à convertir une chaîne de caractères en un nombre entier dans JavaScript ?
a) parseInt()
b) parseFloat()
c) toNumber()
d) toString()
3- Quelle est la méthode utilisée pour exécuter une fonction après un certain délai en JavaScript ?
a) setTimeout()
b) setInterval()
c) setTimein()
d) waitTime()
4- Quelle est la méthode utilisée pour supprimer un élément à la fin d'un tableau en JavaScript ?
a) pop()
b) shift()
c) splice()
d) slice()
5- Comment afficher "Bienvenue" dans la console ?
a) console("Bienvenue");
b) log("Bienvenue");
c) prompt("Bienvenue");
d) [Link]("Bienvenue");

Réservé à l’établissement Code : …………………………………………………………. Page 1 / 5

Surveillant1 :……………………………………………………………….

Surveillant2 :………………………………………………………………. Num Module : M105


6- Comment convertir une chaîne ch1 en minuscules ?
a) Lower(ch1)
b) [Link]()
c) [Link]()
d) Min(ch1)
7- $("p"). Que permet de sélectionner l’instruction précédente ?
a) Tous les éléments paragraphes
b) Le premier élément paragraphe
c) les éléments ayant la classe p
d) va provoquer une erreur
8- Quelle est la méthode jquery permettant de changer le style CSS d’un élément ?
a) html()
b) css()
c) style()
d) attr()

Exercice 2 : (4 points)
Écrivez une fonction JavaScript qui prend un tableau d'entiers et renvoie le maximum des éléments du tableau

……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
Exercice 3 : (4 points)
Que fait le code suivant ?

<body>
<img src="[Link]" alt="image1" id="img1"
onmouseover="afficher()" onmouseout="afficher2()"/>
<p id="p1"> </p>
<script>
img1= [Link]("img1");
p=[Link]("p1");
function afficher()
{[Link]("src","[Link]");
[Link]= [Link]("src"); }
function afficher2()
{[Link]("src","[Link]");
[Link]= [Link]("src"); }
</script>
</body>

……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………

Réservé à l’établissement Code : …………………………………………………………. Page 2 / 5

Surveillant1 :……………………………………………………………….

Surveillant2 :………………………………………………………………. Num Module : M105


……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………

Pratique : ( 24 Points )
On souhaite réaliser un site web permettant de commander des livres informatiques, on supposera que les
données sont stockées dans un tableau ayant la forme suivante :

[{"ISBN":"01234","titre":"Langage C","image":"[Link]","prix":150},
{"ISBN":"56789","titre":"Programmation
Javascript","image":"[Link]","prix":250},
{"ISBN":"11778","titre":"Laravel","image":"[Link]","prix":200}]

Notre site aura l’apparrence suivante :

Figure 1 : site web Achat Livres


1- Écrire le code de la fonction javascript charger() permettant de remplir la liste déroulante avec les titres
des livres stockés dans le tableau (5 pts)
……………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………

Réservé à l’établissement Code : …………………………………………………………. Page 3 / 5

Surveillant1 :……………………………………………………………….

Surveillant2 :………………………………………………………………. Num Module : M105


……………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………
2- Écrire le code de la fonction javascript afficher() permettant d’afficher les informations du livre
sélectionné dans la liste déroulante (voir la figure 1) (5 pts)

……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………

3- Écrire le code la fonction javascript ajouter() permettant d’ajouter un nouveau livre au panier et de
calculer également le prix total à payer. (5 pts)

……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
4- Écrire le code de la fonction javascript retirer() permettant de retirer le livre sélectionné dans la liste
déroulante du panier et de recalculer le prix total à payer. (5 pts)

……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………

Réservé à l’établissement Code : …………………………………………………………. Page 4 / 5

Surveillant1 :……………………………………………………………….

Surveillant2 :………………………………………………………………. Num Module : M105


5- Écrire le code HTML de la page en faisant appel aux fonctions précédentes(4 pts)

……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………………………………………………………………………

Réservé à l’établissement Code : …………………………………………………………. Page 5 / 5

Surveillant1 :……………………………………………………………….

Surveillant2 :………………………………………………………………. Num Module : M105

Common questions

Powered by AI

The function 'afficher()' can override the 'src' attribute of an image element and display its current 'src' in a paragraph. When this function is called, it changes the 'src' attribute of the image and updates the text content of the paragraph with this new 'src' value.

The 'charger()' function populates a dropdown list with the titles of books stored in a predefined collection (likely an array of objects). It iterates over the collection, extracts each book's title, and dynamically inserts these as options in the dropdown, enabling users to select from available titles. This is essential for creating an interactive user interface where selections drive further actions.

The function 'ajouter()' can be used in a shopping cart system by adding a selected book from a list to a cart, updating the cart's inventory, and recalculating the total price to be paid. The function modifies both the display and the underlying data structure (usually an array or similar to store the cart items) reflecting changes in the cart.

In jQuery, you would use the 'css()' method to change the CSS style of a DOM element. This method allows you to set one or more CSS properties for the selected elements.

The 'parseInt()' function is used to convert a string to an integer, handling number conversions within strings. The 'toLowerCase()' method transforms text to lowercase, aiding in consistent data formatting for user inputs or data comparison. These functions are significant for maintaining uniformity and enabling numerical operations on string representations of numbers. They simplify data processing in JavaScript workflows by ensuring data types are correctly converted for further operations.

JavaScript enables dynamic interaction in a web application for book ordering by leveraging functions to manage UI elements and business logic. For example, 'charger()' populates dropdowns with book titles, supporting user selections. Functions like 'ajouter()' handle dynamic cart updates and pricing calculations, enabling real-time feedback on user actions. This interaction between UI and backend data structures represents JavaScript's role in responsive, user-centered web applications, facilitating order management, UI updates, and real-time data interactions.

You can use 'parseInt()' to convert a floating-point string into an integer in JavaScript. To convert a string entirely to lowercase, the 'toLowerCase()' method is used. These methods handle numerical and textual transformations respectively, providing essential functionality in string and number manipulation.

The 'afficher()' function is executed when the mouse hovers over an image element, changing the image source from the original to a new one and displaying this source in a paragraph. Conversely, 'afficher2()' is invoked when the mouse exits the image area, resetting the image source to its original and updating the paragraph with the original source. These functions operate within the context of handling 'mouseover' and 'mouseout' events respectively.

Event-driven functions like 'afficher()' significantly enhance user experience by providing dynamic content change based on user interactions. By reacting to 'mouseover' events, these functions instantaneously update images or related content, creating an engaging and responsive interface. Users receive immediate feedback to their actions, which enriches the interactive nature of the website and improves usability by making it visually informative.

The 'setTimeout()' function is preferred for executing a function once after a specified delay, making it suitable for delayed single-execution actions. 'setInterval()', on the other hand, repeatedly executes a function at specified intervals. When a single execution is required after a delay, 'setTimeout()' is more efficient since it avoids the overhead and potential conflict of continuous execution related to using 'setInterval()'.

Réservé à l’établissement Code : …………………………………………………………. 
  Page 1 / 5 
Surveillant1 :………………………………………………………………. 
Surveillant2
Réservé à l’établissement Code : …………………………………………………………. 
  Page 2 / 5 
Surveillant1 :………………………………………………………………. 
Surveillant2
Réservé à l’établissement Code : …………………………………………………………. 
  Page 3 / 5 
Surveillant1 :………………………………………………………………. 
Surveillant2
Réservé à l’établissement Code : …………………………………………………………. 
  Page 4 / 5 
Surveillant1 :………………………………………………………………. 
Surveillant2
Réservé à l’établissement Code : …………………………………………………………. 
  Page 5 / 5 
Surveillant1 :………………………………………………………………. 
Surveillant2

You might also like