# Optimizing my code

**URL:** https://forum.kirupa.com/t/optimizing-my-code/134134
**Category:** Uncategorized
**Created:** [January 14, 2005, 10:33pm UTC](https://forum.kirupa.com/t/optimizing-my-code/134134 "2005-01-14T22:33:02Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mprzybylski](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mprzybylski/32/613_2.png) [@mprzybylski](https://forum.kirupa.com/u/mprzybylski)
#### Post date: [January 14, 2005, 10:33pm UTC](https://forum.kirupa.com/t/optimizing-my-code/134134/1 "2005-01-14T22:33:02Z")

</div>

I have the following lines of code that i want to optimize:

[AS]furniture1.onRollOver = function() {  
duplicate(furniture1);  
};  
furniture2.onRollOver = function() {  
duplicate(furniture2);  
};  
furniture3.onRollOver = function() {  
duplicate(furniture3);  
};  
furniture4.onRollOver = function() {  
duplicate(furniture4);  
};[/AS]

I tried the following but it wasnt working for me:

[AS]var numOfFurniture = 4;  
for (var i = 1; i \<= numOfFurniture; i++) {  
var furn = this[“furniture” + i];  
furn.onRollOver = duplicate(furn);  
}[/AS]

how can i optimize this so i dont have to write an onRollOver statement for every piece of furniture i add?

thanks in advance.
