It's not over until you win

[Grasshopper] Fundamentals I-9. Climb the Mountain 본문

IT/Grasshopper

[Grasshopper] Fundamentals I-9. Climb the Mountain

캬옹몽몽이 2019. 1. 22. 10:05


9챕터.


Fundamental I에서 배운 걸 모두 응용해 "산에 오른다."로 Clear하는 단계.


1-9-1. State Your Goal


이 챕터에서는 예제를 풀 때 잘못된 걸 고치는 정도가 아니라 처음부터 코딩을 해보라고 주어준다.

쉬운 것부터 어려운 것까지 스스로 해보라는 의미.

처음이니 간단하다.

스토리라인으로 풀어간다. "난 이제 산을 오를거야."


print ( 'I am going to climb a mountain' ) ; 



1-9-2. Pack Your Bag


산을 오르려면 가방을 싸야지. 가방에 넣을 property를 정한다.


var myBackpack = { food : 'bananas', equipment : 'map', clothing : 'hat' } ;

print (myBackpack.food) ;



1-9-3. Get More Supplies


Ranger가 내 가방을 보더니, 물품이 더 필요하니 채우라고 했다. 더 채워보자.

채워야 할 물품은 제시되어 있다.


var myBackpack = { food : ['bananas', 'nuts', 'energybar'] , equipment : ['map', 'compass'],  

  clothing : ['scarf', 'jacket', 'hat'] } ;

print (myBackpack.food) ;

print (myBackpack.equipment) ;

print (myBackpack.clothing) ;



1-9-4. Update Your Progress


자. 이제 산을 오른다. 산의 높이를 측정해보자.

산을 오르기 시작하는 지점은 100 feet에 해당하고 455 feet를 더 올라야 한다.


var elevation = 100 ;

print ( elevation ) ; 

elevation = elevation + 455 ;

print ( elevation ) ;



1-9-5. Backpack Mistake


산에 오르는 중 간식을 먹으려고 멈춰섰는데, 가방에 음식을 덜 쌌다는 걸 알았다. 그게 뭘까.

아래 내용은 이미 주어진 상태다.

var otherBackpack = { food : [ 'crackers', 'chocolate', 'raisins' ],

  equipment : ['map', 'rope', 'compass' ], clothing : ['hat', 'umbrella', 'boots' ] }


for...of를 사용하여, food을 나열하라는 문제라고 보여진다.

for ( var element of otherBackpack.food ) { print ( element ) ; }

food의 property를 element라고 정의하고 그걸 반복해서 나타내라는 의미.



1-9-6. The Final Ascent


후. 마지막의 마지막이다. 정상에 이르기까지 10 feet 남았다. 

rope를 찾아라. 못찾으면 이렇게 내뱉어라. ' A map is not useful right now'

찾았으면 이렇게 내뱉어라. 'I found some rope!'


for ( var element of otherBackpack.equipment ) 

  { if ( element === 'rope' ) { print ('I found some ' + element + '!') ; }

  else { print ( 'A ' + element + ' is not useful right now' ) } }


와! Fundamental I을 끝까지 마쳤다.

Comments