-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion15.js
More file actions
37 lines (24 loc) · 1.03 KB
/
Question15.js
File metadata and controls
37 lines (24 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**15. Fazer um algoritmo para receber um número decimal e o peso de cada
* número até que o usuário digite o número 0. Fazer a média ponderada
* desses números e pesos respectivos.
*/
const prompt = require('prompt-sync')();
function weightedMean(){
let control =true;
let divisor =0;
do{
let decimal01= parseFloat(prompt("First Number : "));
let Weight01= parseFloat(prompt("Weight: "));
let decimal02= parseFloat(prompt("second Number : "));
let Weight02= parseFloat(prompt("Weight: "));
if(isNaN(decimal01) || isNaN(Weight01) || isNaN(decimal02) ||isNaN(Weight02) ){
console.log("Please! Enter a number!");
control = false;
break;
}
divisor = Weight01+Weight02;
let weightedMean = ((decimal01*Weight01)+(decimal02*Weight02))/divisor;
console.log("Weighted mean: ",weightedMean.toFixed(2) );
}while(control)
}
weightedMean();