Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider not introducing the for loop #4

Open
max-mapper opened this issue Oct 9, 2012 · 2 comments
Open

consider not introducing the for loop #4

max-mapper opened this issue Oct 9, 2012 · 2 comments

Comments

@max-mapper
Copy link

https://github.com/OpenTechSchool/js-beginners-4h-workshop-1/blob/gh-pages/page3.html#L98-104

function rainbow(x, y) {
  var colors = ["red", "orange", "yellow", "green", "cyan", "purple", "white"];
  for (var count = 0; count < colors.length; count = count + 1) {
    color(colors[count]);
    circle(x, y, 150 - 5 * count);
  }
}

can be rewritten as

function rainbow(x, y) {
  var colors = ["red", "orange", "yellow", "green", "cyan", "purple",
  colors.forEach(function(color) {
    color(color)
    circle(x, y, 150 - 5 * colors.indexOf(color))
  })
}

since for loops are rather confusing for absolute beginners

@xMartin
Copy link
Member

xMartin commented Oct 9, 2012

Not sure if passing a function that will be called multiple times is less confusing. We could try out this variant when a student has a hard time to get the for loop. Would be cool in general to collect some learn success data.

@janmonschke
Copy link

I'd also say that we should use sth. like forEach here on the first day and introduce loops on the second day in reference to this example maybe since a) the concept of for-loops is very complex for beginners and b) it introduces a lot of new syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants