ReactiveX / learnrx

A series of interactive exercises for learning Microsoft's Reactive Extensions Library for Javascript.
1.4k stars 292 forks source link

Enhancement - Any interest in a helper function to show exercise by number? #176

Open seanpoulter opened 5 years ago

seanpoulter commented 5 years ago

I've noticed that it takes a bit of fiddling to reproduce issues on specific exercises. Would you accept a PR that adds a showLessonByNumber function like:

/**
 * @param {number} n  The lesson number starting from 1
 */
function showLessonByNumber(n) {
  var item = $(".lesson").get(n - 1);
  if (item) {
    showLesson(item);
  } else {
    throw new Error("Exercise " + (n - 1) + " could not be found.");
  }
}

Since this would be the third spot we're changing the visibility of a lesson, I'd suggest we extract that function as showLesson:

/**
 * @param {Element} lessonElement
 */
function showLesson(lessonElement) {
  var post = $(".post", lessonElement)[0];
  lessonElement.style.visibility = "visible";

  if (post !== undefined) { 
    post.style.visibility = "visible"; 
  } 
}

We could call this function in these two spots as well: