jda_m06/uf01/exercicis_uf01_02/exercic_17.html
2022-02-16 16:13:08 +01:00

47 lines
809 B
HTML
Executable file

<!DOCTYPE html>
<html>
<body>
<h2>Exercicis JavaScript UF01 2</h2>
<h3>Jan Maroto</h3>
<h4 id="demo"></h4>
<script>
function rand(min, max){
return Math.floor(Math.random() * (max - min + 1)) + min;
}
while(true)
userNumber = prompt("Introdueïx el teu nom");
machineNumber = rand(1, 100);
nCharA = 0;
nCharB = 0;
[...input].forEach(firstFunction);
if (nCharA == nCharB) {
text = "Hi han el mateix nombre de as que de bs";
} else {
text = "No hi han el mateix nombre de as que de bs";
}
function firstFunction(char) {
if (char == 'a') {
++nCharA;
} else if (char == 'b') {
++nCharB;
}
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>