Repository: freeCodeCamp/freeCodeCamp
File: client/src/templates/Challenges/redux/execute-challenge-saga.js (JavaScript)

Code before:
    const isBlockCompleted = yield select(isBlockNewlyCompletedSelector);
    if (challengeComplete) {
      playTone('tests-completed');
      if (isBlockCompleted) {
        fireConfetti();
      }
    } else {
      playTone('tests-failed');
      if (challengeMeta.certification === 'responsive-web-design') {
        yield call(callGA, {
          event: 'challenge_failed',
          challenge_id: challengeMeta.id,
          challenge_path: window?.location?.pathname,
          challenge_files: challengeData.challengeFiles
        });
      }
    }

    if (challengeComplete && payload?.showCompletionModal) {
      let canOpenModal = sessionStorage.getItem('canOpenModal');

      if (canOpenModal === 'false') {
        // do nothing
      } else {
        yield put(openModal('completion'));
      }
    }
    yield put(updateConsole(i18next.t('learn.tests-completed')));
    yield put(logsToConsole(i18next.t('learn.console-output')));
  } catch (e) {
    yield put(updateConsole(e));
  } finally {
    yield put(executeChallengeComplete());
    consoleProxy.close();
  }
}

function* takeEveryLog(channel) {
  // TODO: move all stringifying and escaping into the reducer so there is a
  // single place responsible for formatting the logs.
  yield takeEvery(channel, function* (args) {
    yield put(updateLogs(escape(args)));
  });
}

function* takeEveryConsole(channel) {
  // TODO: move all stringifying and escaping into the reducer so there is a
  // single place responsible for formatting the console output.
  yield takeEvery(channel, function* (args) {
    yield put(updateConsole(escape(args)));
  });

Review comment (suggestion):
```suggestion
      if (canOpenModal !== 'false') {
        yield put(openModal('completion'));
      }
```

We definitely shouldn't be using an `if/else` with an empty `if` block.

Code after:
    const isBlockCompleted = yield select(isBlockNewlyCompletedSelector);
    if (challengeComplete) {
      playTone('tests-completed');
      if (isBlockCompleted) {
        fireConfetti();
      }
    } else {
      playTone('tests-failed');
      if (challengeMeta.certification === 'responsive-web-design') {
        yield call(callGA, {
          event: 'challenge_failed',
          challenge_id: challengeMeta.id,
          challenge_path: window?.location?.pathname,
          challenge_files: challengeData.challengeFiles
        });
      }
    }

    if (challengeComplete && payload?.showCompletionModal) {
      yield put(openModal('completion'));
    }
    yield put(updateConsole(i18next.t('learn.tests-completed')));
    yield put(logsToConsole(i18next.t('learn.console-output')));
  } catch (e) {
    yield put(updateConsole(e));
  } finally {
    yield put(executeChallengeComplete());
    consoleProxy.close();
  }
}

function* takeEveryLog(channel) {
  // TODO: move all stringifying and escaping into the reducer so there is a
  // single place responsible for formatting the logs.
  yield takeEvery(channel, function* (args) {
    yield put(updateLogs(escape(args)));
  });
}

function* takeEveryConsole(channel) {
  // TODO: move all stringifying and escaping into the reducer so there is a
  // single place responsible for formatting the console output.
  yield takeEvery(channel, function* (args) {
    yield put(updateConsole(escape(args)));
  });
}

function* buildChallengeData(challengeData, options) {
  try {
    return yield call(buildChallenge, challengeData, options);
  } catch (e) {