this lift programm:
var person = { name: "roman", position: 7, goal: 9 }; var lift = { getposition: function() { var x = math.floor((math.random() * 10) + 1); return x; }() }; console.log("ok " + person.name + "! @ " + person.position + " floor"); console.log("lift @ " + lift.getposition + " floor"); if (lift.getposition > person.position) { (i = lift.getposition; >= person.position; i--) { console.log(i); } } else if (lift.getposition < person.position) { (i = lift.getposition; <= person.position; i++) { console.log(i); } } console.log("please enter inside!"); for loop raising lift doesn't work. lift falling not raising. what's wrong?
you've capitalized position in second loop.
should
for (i = lift.getposition; <= person.position; i++) { (with lowercase p in person.position)
since there no position property in lift object, loop condition asking if i <= undefined. evaluate false , therefore loop never iterates.
Comments
Post a Comment