Alfonso has to work for the $340 - $40 = $<<300=300>>300.
In a week, he earns $6 x 5 = $<<6*5=30>>30.
Thus, he needs to work $300/$30 = <<300/30=10>>10 weeks to buy the bike.
#### 10