JavaScript - No aparecen las estrellas

 
Vista:
sin imagen de perfil

No aparecen las estrellas

Publicado por Josue (1 intervención) el 18/01/2018 03:07:19
Hola,

Hice un código para que me dibujara dos libros con sus datos pero el número de estrellas de cada libro no aparece en el primero. Debe ser por el aumento de i pero no sé cómo arreglar esto.

Gracias por su ayuda!

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
39
40
41
42
43
44
45
46
47
var book = [
    {title: "The Giver",
    stars: 4,
    author: "no sé",
    backgroundColor: color(0, 213, 255),
    recommend: false
    },
    {title: "Caballo de Troya",
    stars: 5,
    author: "J.J. Benitez",
    backgroundColor: color(255, 3, 3),
    recommend: true
    }
];
 
//Font
var f = createFont("cursive");
 
// draw shelf
for (var espacio = 3; espacio <100;espacio++){
    if(espacio%2){
        fill(173, 117, 33);
        rect(0, espacio*49 + -27, width, 10);
    }
}
 
 
// draw books
for (var i = 0; i < book.length; i++) {
    fill(book[i].backgroundColor);
    rect(i*102, 20, 93, 100);
    fill(0, 0, 0);
    textSize(15);
    text(book[i].title, i*108, 29, 70, 100);
    textSize(12);
    text("Author: "+ book[i].author,i*108,68,70,100);
 
    for (var s = 0; s < book[i].stars; s++){
        image(getImage("cute/Star"),s*18+102,90,24,33);
    }
 
    if (book[i].recommend){
        textFont(f,13);
        text("¿Leer?",i*124,16);
        image(getImage("creatures/Hopper-Cool"),87+i*81,2,30,30);
    }
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder