Git Product home page Git Product logo

js-exercices's Introduction

js-exercices's People

Contributors

boummissesofia avatar e-chams avatar enniouarmohammed avatar hamzaennaji avatar hamzajamaldev avatar hvfidolov avatar idriss975 avatar medafkari avatar nin-oh avatar oussama166 avatar rimwakil avatar skafeendri avatar younesslz10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

js-exercices's Issues

js file

// Écrivez un programme JavaScript pour calculer
// la somme des multiples de 3 et 5 inférieurs
// à 50 (utiliser une boucle for).

let somme = 0;
let affiche = "";
for (let i = 1; i < 100; i++) {
if (i % 3 === 0 && i % 5 === 0) {
affiche += i === 15 ? ${i} : + ${i} ;
somme += i;
}
}
affiche += =;
console.log(affiche + somme);

// Écrivez un programme JavaScript pour séparer
// les valeurs paires et impaires d'un tableau en deux
// tableaux (l'ordre n'est pas important).

// Exemple : [1, -2, 3, 0, -1] -> [1, 3, 0] et [-2, -1]

function separationImpPair(tab) {
let pai = [];
let impaire = [];
for (let i = 0; i < tab.length; i++)
tab[i] % 2 === 0 ? pai.push(tab[i]) : impaire.push(tab[i]);
return [pai, impaire];
}

separationImpPair([1, -2, 3, 0, -1]).forEach((el) => console.log(el));

// <===========================> //

// Écrivez un constructeur appelé Chapitre, qui a 3 propriétés :

// nom : une chaîne de caractères.
// nombre_pages : un nombre.
// position : un nombre.

function Chapitre(nom, nombre_pages, pages) {
this.nom = nom;
this.nombre_pages = nombre_pages;
this.pages = pages;
}

// Écrivez la méthode suivante :

// chapitreLong : ne prend aucun paramètre,
// et renvoie true si le nombre de pages
// est supérieur à 100, sinon false.

Chapitre.prototype.chapitreLong = () => this.nombre_pages > 100;

// Écrivez un constructeur appelé Livre, qui a 4 propriétés :

// id : un nombre.
// titre : une chaîne de caractères.
// prix : un nombre.
// chapitres : un tableau d'objets créés à partir du constructeur Chapitre.

function Livre(id, titre, prix, chapitres) {
this.id = id;
this.titre = titre;
this.prix = prix;
this.chapitres = chapitres;
}

// Écrivez les méthodes suivantes :

// sauterLongsChapitres : ne prend aucun paramètre, ne renvoie rien,
// et supprime les chapitres longs de plus de 100 pages.

Livre.prototype.sauterLongsChapitres = function () {
this.chapitres.forEach((chap, index) => {
if (chap.nombre_pages > 100) {
this.chapitres.splice(index, 1);
}
});
};

// trierChapitres : prend un argument (soit "position", soit "nombre_pages"),
// ne retourne rien, et trie les chapitres par position ou par nombre de pages.
Livre.prototype.trierChapitres = function (prop) {
let chapitreTrier = this.chapitres.sort((currChap, nextChap) => {
if (currChap[prop] > nextChap[prop]) {
return 1;
} else {
return -1;
}
});
console.table(chapitreTrier);
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.