It's not over until you win

[Grasshopper] Fundamentals I - 3. Arrays 본문

IT/Grasshopper

[Grasshopper] Fundamentals I - 3. Arrays

캬옹몽몽이 2019. 1. 11. 12:54

3번째 챕터를 진행해보자.

Arrays(배열)를 배운다.



1-3-1. Magic Answers


var answer = pickRandom ([

'yes', 

'no',

'outlook good'

'certainly'

]);

print (answer) ;


pickrandom이라는 건 단어뜻만 보고 유추해본다. 무작위로 고른다. 

그러니까, 여기서 array라는 건 위에 'yes', 'certainly'를 말한다는 걸 알려주는거다.

배열내에 있는 내역들 Print할 경우 무작위로 보여달라는 의미.



1-3-2. Bake a Cake


Array가 작동하는 방식을 알려준다. array를 쓰려면 [ ] 안에 내용을 넣으라는거지.


var ingredients = [ 

'flour',

'sugar',

'eggs'

];

cook (ingredient) ;



1-3-3. A Dash of Color


응용문제. 간단함. 


var listofcolor = [ orange, red, blue, black ];

drawBox (pickrandom (listofcolor)) ;



1-3-4. Created an Array


JavaScript에서 Array라는 건 아이템 목록이라는 설명. 이게 문자열일수도, 숫자일수도, 다른 형태의 Array일수도 있다.



1-3-5. Whose Shoes?


퀴즈. array가 저장된 Variable(변수)은 어느것? 

(Variable, 변수라는 말이 참 익숙하지가 않다.


var myShoes = 'sneakers, highHeels, pumps' ;

var yourShoes = [ 'sneakers', ;highHeels', 'pumps ] ;

var shoeColor - drawBox (Blue) ;



1-3-6. Checkerboard


array index는 0부터 시작한다는걸 배운다.


var colors = [ 'black', 'white' ] ;

drawBox ( color[0] ) ;

drawBox ( color[1] ) ;
drawBox ( color[0] ) ;
newLine ( ) ;
drawBox ( color[1] ) ;
drawBox ( color[0] ) ;
drawBox ( color[1] ) ;
newLine ( ) ;
drawBox ( color[0] ) ;
drawBox ( color[1] ) ;
drawBox ( color[0] ) ;


index 순서에 따라, black은 0이 되고, white는 1이 되는거지.



1-3-7. Used Array Indexing


Array index에 대한 자세한 설명. 대부분 프로그래밍 언어에선, arrays는 0에서 시작한다는 것.


세번째까지 마쳤다.

Comments