Porting the Release Note
In this project, you ported the release note script to JavaScript, checked it, and ran it. Two parts are left for the exercise after this video: the code-freeze warning, which reads the code-freeze setting, and the closing message.
- JavaScript has no docstrings, so the docstring becomes a JSDoc block, a block comment that
opens with an extra star. The
#comment turns into//. - Each setting gets a
constand keeps its capitals, as many projects write top-level settings that someone edits. In Python, nothing stops you reassigning a setting;constmakes JavaScript refuse a second assignment. Watch out for Python’s capitalTrue: JavaScript writestrueandfalsein lowercase, andTruewould stop the file with a reference error before it printed anything. open_bugsbecomes camelCase,openBugs, and stays aconst, since nothing reassigns it.- The status line is a
let, and an if-else block sets it. Python’s line is a one-line conditional expression, but JavaScript’sifis a statement, so it can’t sit on the right of an=. JavaScript has a shorter form for this, which you’ll meet later; for now, anif/elsedoes it. - The two prints turn into
console.log()calls, each f-string a template literal. - The bug check keeps its
ifandelse, in braces. Itsifhas one line, and the port braces it anyway, so a line someone adds later lands inside the block. - The
elseholds only apassplaceholder and a reminder. Empty braces are already a block, so the port dropspassand keeps the reminder inside as a comment. JavaScript has nopass: it would read it as a name and stop on the first day with no open bugs. - Both deployers are
lets, because the swap reassigns them, and the swap becomes destructuring, with square brackets on both sides. Each plain statement ends with a semicolon, and the one after"Theo"matters most, because the next line starts with a bracket. Without it, the two lines would join: the bracket would index the string, and the run would stop with an error.
Here’s the port, release-note.js, with the code-freeze warning and the closing message still to
come:
/**
* Print the end-of-day release note.
*/
// Edit these settings before each run.
const CLIENT = "Fernleaf Bakery";
const VERSION = "2.4.1";
const DEPLOYED_BY = "Maya";
const BUGS_OPENED = 9;
const BUGS_CLOSED = 7;
const CODE_FREEZE = true;
const openBugs = BUGS_OPENED - BUGS_CLOSED;
let statusLine;
if (openBugs === 0) {
statusLine = "all clear";
} else {
statusLine = "needs attention";
}
console.log(`Release ${VERSION} for ${CLIENT}`);
console.log(`Status: ${statusLine}`);
if (openBugs > 0) {
console.log("Open bugs:", openBugs);
} else {
// TODO: link the bug tracker
}
let deployer = DEPLOYED_BY;
let nextDeployer = "Theo";
[deployer, nextDeployer] = [nextDeployer, deployer];
console.log("Next:", deployer, "then", nextDeployer);