Markdown
Markdown is a popular and simple code syntax used to indicate the style of text for display. We’re learning Markdown for two reasons:
Reason 1) It’s a good way to “dip our toes” into programming and get familiar with the process of writing code and having it produce some result.
Reason 2) Markdown is widely used across many different programming contexts. Here are some of the places you’ll encounter it:
- In our course forum as well as public tech forums (e.g. StackOverflow, jsPsych forum)
- R has a “notebook” feature that allow you to present code alongside notes and documentation. These notebooks are written using Markdown.
- Code projects often include README.md files (written in Markdown) that contain information/documentation about the project (example). You will write a README.md file for the project you create in this course.
Markdown basics
The following is a quick reference sheet of the basic Markdown syntax you’ll need to know for this course. Paste this code into a reply to this post in the course forum and switch to the Preview tab to see how it’s rendered.
## Basic text formatting **This text is bold - it must be important** _This text is italicized; you should probably pay attention to it..._ [Click this link to learn about jsPsych...](https://www.jspsych.org) Lists are created using asterisks or plus signs: + Item 1 + Item 2 + Items can be nested via indentation ## Code Inline code can be styled using backticks like this: `alert('hi!');` Blocks of code can be formatted by surrounding them in “code fences”, indicated by three backticks (```) The starting code fence should include the language extension for the code being used. In the following example that's `js` for JavaScript code. Example code block: ```js document.write('Hello World!'); for (let i of [1, 2, 3]) { document.write(i); } ```
Learn more
For more on working in Markdown, check out the following resources from MarkdownGuide.org:
Practice
Using the reference sheet above, write some Markdown code that produces the following styled content:
- Your first name in bold text followed by where you’re from in italicized text
- An unordered list of three books you’ve enjoyed, with links to their Wikipedia pages (or Amazon page if no Wiki exists).
- A block of syntax highlighted JavaScript code that contains this content:
function generateRandomLetters(length) {
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
let result = '';
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * alphabet.length);
result += alphabet[randomIndex];
}
return result;
}
document.write(generateRandomLetters(5));
You can write this practice Markdown in a reply to this thread in the forum and use the Preview option to confirm everything is rendering as expected before posted.
Here’s an example of what the rendered results should look like: