+ 1

How to reduce my code

I'm doing a little page to try what I learnt. it's pretty simple, when you click a color appears and you can save it in the box on the side. I would create a function that put the color in the big rectangle in a smaller one. for the moment it works but I wrote 4 times the function just changing the rectangle to fill. how can I create a function I can call and define easily without have to write it again and again? https://code.sololearn.com/W3KgFIp9ApsN/?ref=app

17th Jun 2018, 7:04 AM
Tom Lecaudey
Tom Lecaudey - avatar
3 Respostas
+ 5
https://code.sololearn.com/WGh82dkBYm7g/?ref=app
17th Jun 2018, 7:47 AM
Calviղ
Calviղ - avatar
+ 2
haw yeah ok.. I'll try to understand that ! cheers
17th Jun 2018, 8:12 AM
Tom Lecaudey
Tom Lecaudey - avatar
0
I'm trying to figure out but I stay stuck on this part : x = x==colors.lenght-1? x=0:x+1 I understand that it is used for increment x, or reset the value of x if x = colors.lenght-1. what I don't get is the "x= x==" ... not sure I'm really clear aha
17th Jun 2018, 9:37 AM
Tom Lecaudey
Tom Lecaudey - avatar