0% found this document useful (0 votes)
2 views3 pages

Corr V2.js

The document contains JavaScript functions for various mathematical and date-related operations. Functions include calculating the sum of two positive numbers, finding solutions to linear equations, computing factorials, summing odd numbers, incrementing dates, and counting letter presses based on specific criteria. Each function utilizes prompts for user input and displays results in an HTML element with the ID 'corr'.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Corr V2.js

The document contains JavaScript functions for various mathematical and date-related operations. Functions include calculating the sum of two positive numbers, finding solutions to linear equations, computing factorials, summing odd numbers, incrementing dates, and counting letter presses based on specific criteria. Each function utilizes prompts for user input and displays results in an HTML element with the ID 'corr'.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

function f1() {

let a, b;
do {
a = Number(prompt("A = "));
b = Number(prompt("B = "));
} while (!(a > 0 && b > 0));
document.getElementById("corr").innerHTML = a + b;
}

function ex2() {
var a, b, ch;
a = Number(prompt("A = "));
b = Number(prompt("B = "));
if (a == 0) {
if (b == 0) {
document.getElementById("corr").innerHTML = "R";
} else {
document.getElementById("corr").innerHTML = "Pas de Solution ";
}
} else {
document.getElementById("corr").innerHTML = "Solution = " + -b / a;
}
}
function ex3() {
var n;
do {
n = Number(prompt("N = "));
} while (!(n > 0));

f = 1;
for (let i = 2; i <= n; i++) {
f = f * i;
}
document.getElementById("corr").innerHTML = "Factorielle de " + n + " = " + f;
}

function ex4() {
let n, s1;
do {
n = Number(prompt("N = "));
} while (!(n > 0));
s1 = 0;

for (let i = 1; i <= n; i = i + 2) {


s1 = s1 + i;
}
document.getElementById("corr").innerHTML = "Somme S1 = " + s1;
}

function ex5() {
var j, m, a;
do {
j = Number(prompt("Jours = "));
m = Number(prompt("Mois = "));
a = Number(prompt("Année = "));
} while (!(j >= 1 && j <= 31 && m >= 1 && m <= 12 && a >= 1000));
switch (m) {
case 4:
case 6:
case 9:
case 11:
if (j < 30) {
j = j + 1;
ch = j + "/" + m + "/" + a;
} else if (j == 30) {
j = 1;
m = m + 1;
ch = j + "/" + m + "/" + a;
} else {
ch = "Date Invalide ";
}
break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
if (j < 31) {
j = j + 1;
ch = j + "/" + m + "/" + a;
} else {
j = 1;
m = m + 1;
ch = j + "/" + m + "/" + a;
}
break;
case 12:
if (j < 31) {
j = j + 1;
ch = j + "/" + m + "/" + a;
} else {
j = 1;
m = 1;
a = a + 1;
ch = j + "/" + m + "/" + a;
}
break;
case 2:
if (j < 28) {
j = j + 1;
ch = j + "/" + m + "/" + a;
} else if (j == 28) {
if (a % 4 == 0) {
j = j + 1;
ch = j + "/" + m + "/" + a;
} else {
j = 1;
m = 3;
ch = j + "/" + m + "/" + a;
}
} else if (j == 29) {
j = 1;
m = 3;
ch = j + "/" + m + "/" + a;
} else {
ch = "Date Invalide ";
}
}
document.getElementById("corr").innerHTML = ch;
}

function ex6() {
var ch, nb;
do {
ch = prompt("Mots = ");
} while (!alphmajus(ch));
nb = 0;
for (let i = 0; i < ch.length; i++) {
switch (ch[i]) {
case "S":
case "Z":
nb = nb + 4;
break;
case "A":
case "D":
case "G":
case "J":
case "M":
case "P":
case "T":
case "W":
nb = nb + 1;
break;
case "B":
case "E":
case "H":
case "K":
case "N":
case "Q":
case "U":
case "X":
nb = nb + 2;
break;
default:
nb = nb + 3;
break;
}
}
document.getElementById("corr").innerHTML = "Nombre des Apuis = " + nb;
}

function alphmajus(ch) {
for (let i = 0; i < ch.length; i++) {
if (ch[i] > "Z" || ch[i] < "A") {
return false;
}
}
return true;
}

You might also like