Added results for exo 3.
This commit is contained in:
1 parent
2af0ba2d06
commit
0c82baef38
4 files changed
+386
No files matched your search
@@ -0,0 +1,96 @@
|
|||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>title</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column">
|
||||||
|
<h1 class="title" id="main-title">#main-title</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column">
|
||||||
|
<div class="notification is-primary" id="result-box-1">
|
||||||
|
<strong>#result-box-1</strong>
|
||||||
|
<br>
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<div class="notification is-warning" id="result-box-2">
|
||||||
|
<strong>#result-box-2</strong>
|
||||||
|
<br>
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<div class="notification is-primary is-light" id="result-box-3">
|
||||||
|
<strong>#result-box-3</strong>
|
||||||
|
<br>
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<div class="notification is-warning is-light" id="result-box-4">
|
||||||
|
<strong>#result-box-4</strong>
|
||||||
|
<br>
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column">
|
||||||
|
<label>
|
||||||
|
#input-1
|
||||||
|
<input class="input" placeholder="Text input" type="text" id="input-1">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<label>
|
||||||
|
#input-2
|
||||||
|
<input class="input" placeholder="Text input" type="text" id="input-2">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<label>
|
||||||
|
#input-3
|
||||||
|
<input class="input" placeholder="Text input" type="text" id="input-3">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<label>
|
||||||
|
#input-4
|
||||||
|
<input class="input" placeholder="Text input" type="text" id="input-4">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column">
|
||||||
|
<button type="button" class="button is-primary" id="button-1" onclick="exo1b()">#button-1</button>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<button type="button" class="button is-warning" id="button-2" onclick="exo1c()">#button-2</button>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<button type="button" class="button is-primary is-light" id="button-3" onclick="exo1d()">#button-3</button>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<button type="button" class="button is-warning is-light" id="button-4" onclick="exo1e()">#button-4</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="exo3.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
document.getElementById("main-title").innerText = "Los Statisticos";
|
||||||
|
|
||||||
|
function isNumber(str) {
|
||||||
|
return str !== "" && !isNaN(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isInputBoxANumericValue(maxIdValue) {
|
||||||
|
let userInput = document.getElementById("input-" + maxIdValue).value;
|
||||||
|
return isNumber(userInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
function booleanToNumber(trueOrFalse) {
|
||||||
|
if (trueOrFalse) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function countNumberOfNumericValuesInInputBoxes(maxIdValue) {
|
||||||
|
const ret = booleanToNumber(isInputBoxANumericValue(maxIdValue));
|
||||||
|
if (maxIdValue === 1) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
return ret + countNumberOfNumericValuesInInputBoxes(maxIdValue - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getInputValueAsNumber(maxIdValue) {
|
||||||
|
let userInput = document.getElementById("input-" + maxIdValue).value;
|
||||||
|
if(isNumber(userInput)){
|
||||||
|
return parseFloat(userInput);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function sumNumericValuesInInputBoxes(maxIdValue) {
|
||||||
|
if(maxIdValue === 1){
|
||||||
|
return getInputValueAsNumber(maxIdValue);
|
||||||
|
}
|
||||||
|
return getInputValueAsNumber(maxIdValue) + sumNumericValuesInInputBoxes(maxIdValue - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sumOfSquareOfNumericValuesInInputBoxes(maxIdValue){
|
||||||
|
let ret = getInputValueAsNumber(maxIdValue) * getInputValueAsNumber(maxIdValue);
|
||||||
|
if(maxIdValue === 1){
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
return ret + sumOfSquareOfNumericValuesInInputBoxes(maxIdValue - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function averageNumericValuesInInputBoxes(maxIdValue) {
|
||||||
|
let sum = sumNumericValuesInInputBoxes(maxIdValue);
|
||||||
|
let n = countNumberOfNumericValuesInInputBoxes(maxIdValue);
|
||||||
|
return sum / n;
|
||||||
|
}
|
||||||
|
|
||||||
|
function averageSquareOfNumericValuesInInputBoxes(maxIdValue) {
|
||||||
|
let sumOfSquare = sumOfSquareOfNumericValuesInInputBoxes(maxIdValue);
|
||||||
|
let n = countNumberOfNumericValuesInInputBoxes(maxIdValue);
|
||||||
|
return sumOfSquare / n;
|
||||||
|
}
|
||||||
|
|
||||||
|
function standardDeviationOfNumericValues(maxIdValue){
|
||||||
|
let avg = averageNumericValuesInInputBoxes(maxIdValue);
|
||||||
|
let avgOfTheSquare = averageSquareOfNumericValuesInInputBoxes(maxIdValue);
|
||||||
|
return Math.sqrt(avgOfTheSquare - avg * avg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function exo1b() {
|
||||||
|
let numericValuesInInputBoxes = countNumberOfNumericValuesInInputBoxes(4);
|
||||||
|
document.getElementById("result-box-1").innerText = numericValuesInInputBoxes;
|
||||||
|
}
|
||||||
|
|
||||||
|
function exo1c() {
|
||||||
|
let avg = averageNumericValuesInInputBoxes(4)
|
||||||
|
document.getElementById("result-box-2").innerText = avg;
|
||||||
|
}
|
||||||
|
|
||||||
|
function exo1d() {
|
||||||
|
let standardDeviation = standardDeviationOfNumericValues(4)
|
||||||
|
document.getElementById("result-box-3").innerText = standardDeviation;
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>title</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column">
|
||||||
|
<h1 class="title" id="main-title">#main-title</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column">
|
||||||
|
<div class="notification is-primary" id="result-box-1">
|
||||||
|
<strong>#result-box-1</strong>
|
||||||
|
<br>
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<div class="notification is-warning" id="result-box-2">
|
||||||
|
<strong>#result-box-2</strong>
|
||||||
|
<br>
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<div class="notification is-primary is-light" id="result-box-3">
|
||||||
|
<strong>#result-box-3</strong>
|
||||||
|
<br>
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<div class="notification is-warning is-light" id="result-box-4">
|
||||||
|
<strong>#result-box-4</strong>
|
||||||
|
<br>
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column">
|
||||||
|
<label>
|
||||||
|
#input-1
|
||||||
|
<input class="input" placeholder="Text input" type="text" id="input-1">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<label>
|
||||||
|
#input-2
|
||||||
|
<input class="input" placeholder="Text input" type="text" id="input-2">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<label>
|
||||||
|
#input-3
|
||||||
|
<input class="input" placeholder="Text input" type="text" id="input-3">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<label>
|
||||||
|
#input-4
|
||||||
|
<input class="input" placeholder="Text input" type="text" id="input-4">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column">
|
||||||
|
<button type="button" class="button is-primary" id="button-1" onclick="exo1b()">#button-1</button>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<button type="button" class="button is-warning" id="button-2" onclick="exo1c()">#button-2</button>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<button type="button" class="button is-primary is-light" id="button-3" onclick="exo1d()">#button-3</button>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<button type="button" class="button is-warning is-light" id="button-4" onclick="exo1e()">#button-4</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="exo3_no_loops.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
document.getElementById("main-title").innerText = "Los Statisticos (sans loop)";
|
||||||
|
|
||||||
|
function isNumber(str) {
|
||||||
|
return str !== "" && !isNaN(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
function countNumberOfNumericValues(value1, value2, value3, value4){
|
||||||
|
let ret = 0;
|
||||||
|
if(isNumber(value1)){
|
||||||
|
ret = ret + 1;
|
||||||
|
}
|
||||||
|
if(isNumber(value2)){
|
||||||
|
ret = ret + 1;
|
||||||
|
}
|
||||||
|
if(isNumber(value3)){
|
||||||
|
ret = ret + 1;
|
||||||
|
}
|
||||||
|
if(isNumber(value4)){
|
||||||
|
ret = ret + 1;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sumSquareOfNumberOfNumericValues(value1, value2, value3, value4){
|
||||||
|
let ret = 0;
|
||||||
|
if(isNumber(value1)){
|
||||||
|
ret = ret + parseFloat(value1) * parseFloat(value1);
|
||||||
|
}
|
||||||
|
if(isNumber(value2)){
|
||||||
|
ret = ret + parseFloat(value2) * parseFloat(value2);
|
||||||
|
}
|
||||||
|
if(isNumber(value3)){
|
||||||
|
ret = ret + + parseFloat(value3) * parseFloat(value3);
|
||||||
|
}
|
||||||
|
if(isNumber(value4)){
|
||||||
|
ret = ret + + parseFloat(value4) * parseFloat(value4);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
function sumNumberOfNumericValues(value1, value2, value3, value4) {
|
||||||
|
let ret = 0;
|
||||||
|
if(isNumber(value1)){
|
||||||
|
ret = ret + parseFloat(value1);
|
||||||
|
}
|
||||||
|
if(isNumber(value2)){
|
||||||
|
ret = ret + parseFloat(value2);
|
||||||
|
}
|
||||||
|
if(isNumber(value3)){
|
||||||
|
ret = ret + + parseFloat(value3);
|
||||||
|
}
|
||||||
|
if(isNumber(value4)){
|
||||||
|
ret = ret + + parseFloat(value4);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
function averageNumericValues(value1, value2, value3, value4) {
|
||||||
|
let n = countNumberOfNumericValues(value1, value2, value3, value4);
|
||||||
|
let sum = sumNumberOfNumericValues(value1, value2, value3, value4);
|
||||||
|
return sum / n;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun
|
||||||
|
|
||||||
|
function averageSquareOfNumericValues(value1, value2, value3, value4) {
|
||||||
|
let n = countNumberOfNumericValues(value1, value2, value3, value4);
|
||||||
|
let sumOfSquare = sumSquareOfNumberOfNumericValues(value1, value2, value3, value4);
|
||||||
|
return sumOfSquare / n;
|
||||||
|
}
|
||||||
|
|
||||||
|
function standardDeviationOfNumericValues(value1, value2, value3, value4) {
|
||||||
|
let avg = averageNumericValues(value1, value2, value3, value4);
|
||||||
|
let avgOfTheSquare = averageSquareOfNumericValues(value1, value2, value3, value4);
|
||||||
|
return Math.sqrt(avgOfTheSquare - avg * avg);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function exo1b() {
|
||||||
|
let input1 = document.getElementById("input-1").value;
|
||||||
|
let input2 = document.getElementById("input-2").value;
|
||||||
|
let input3 = document.getElementById("input-3").value;
|
||||||
|
let input4 = document.getElementById("input-4").value;
|
||||||
|
|
||||||
|
|
||||||
|
let numericValuesInInputBoxes = countNumberOfNumericValues(input1, input2, input3, input4);
|
||||||
|
document.getElementById("result-box-1").innerText = numericValuesInInputBoxes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function exo1c() {
|
||||||
|
let input1 = document.getElementById("input-1").value;
|
||||||
|
let input2 = document.getElementById("input-2").value;
|
||||||
|
let input3 = document.getElementById("input-3").value;
|
||||||
|
let input4 = document.getElementById("input-4").value;
|
||||||
|
|
||||||
|
|
||||||
|
let avg = averageNumericValues(input1, input2, input3, input4);
|
||||||
|
document.getElementById("result-box-2").innerText = avg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function exo1d() {
|
||||||
|
let input1 = document.getElementById("input-1").value;
|
||||||
|
let input2 = document.getElementById("input-2").value;
|
||||||
|
let input3 = document.getElementById("input-3").value;
|
||||||
|
let input4 = document.getElementById("input-4").value;
|
||||||
|
|
||||||
|
|
||||||
|
let standardDeviation = standardDeviationOfNumericValues(input1, input2, input3, input4);
|
||||||
|
document.getElementById("result-box-3").innerText = standardDeviation;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user