-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclase14.js
More file actions
38 lines (30 loc) · 797 Bytes
/
clase14.js
File metadata and controls
38 lines (30 loc) · 797 Bytes
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
38
var Martin = {
nombre: 'Martin',
apellido: 'Maceda',
edad: 28,
peso: 65
}
console.log(`Al Inicio del ano ${Martin.nombre} pesa: ${Martin.peso}kg`);
//function aumentarPeso (persona) {
// return persona.peso += 200
//}
const CAMBIO_PESO = 0.3
const DIAS_DEL_ANO = 365
const aumentarPeso = (persona) => persona.peso += CAMBIO_PESO
const adelgazar = (persona) => persona.peso -= CAMBIO_PESO
const comeMucho = () => Math.random() < 0.3
const realizaDeporte = () => Math.random() < 0.4
const META = Martin.peso - 3
var dias = 0
while (Martin.peso > META) {
if (comeMucho()) {
//aumentaPeso
aumentarPeso(Martin)
}
if (realizaDeporte()) {
//adelgazar
adelgazar(Martin)
}
dias += 1
}
console.log(`Pasaron ${dias} dias hasta que ${Martin.nombre} adelgazo 3 kg`);