文章中嵌入代碼塊_如何在您的文章中嵌入多項選擇測驗問題

文章中嵌入代碼塊

In my experience, supplementing study with practical exercises greatly improves my understanding of a topic. This is especially true when I can test my knowledge as I go and receive instant feedback for each question.

以我的經驗,通過實踐練習補充學習可以極大地提高我對某個主題的理解。 當我可以隨時測試自己的知識并收到每個問題的即時反饋時,尤其如此。

The multiple choice quiz format is perfect for this. I developed a method to embed multiple choice questions in the math articles I write for freeCodeCamp, and I want to show other authors how to do the same.

多項選擇測驗格式是完美的選擇。 我開發了一種方法,可以在為freeCodeCamp編寫的數學文章中嵌入多項選擇題,并且我想向其他作者展示如何做。

如何在文章中添加代碼 (How to add code to your article)

The Ghost editor allows you to embed blocks of code throughout an article. The code editor can be accessed by clicking the round button with a plus sign (+) used for adding images, YouTube videos, and so on:

Ghost編輯器使您可以在整個文章中嵌入代碼塊。 可以通過單擊帶有加號(+)的圓形按鈕來訪問代碼編輯器,該加號用于添加圖像,YouTube視頻等:

Click on the "HTML" button to add an editor to the article. The editor supports HTML, CSS, and even JavaScript.

單擊“ HTML”按鈕,將編輯器添加到文章。 該編輯器支持HTML,CSS甚至JavaScript。

Once you start adding code, click anywhere outside the editor frame to render the code and view your progress. Double click on the rendered output to reopen the editor window:

一旦開始添加代碼,請在編輯器框架之外的任何位置單擊以呈現代碼并查看進度。 雙擊渲染的輸出以重新打開編輯器窗口:

To test the functionality of your code, save the article by pressing Ctrl/? + S, then click on the "View Preview" button that appears in the bottom left corner:

要測試代碼的功能,請按Ctrl /?+ S保存文章,然后單擊左下角出現的“查看預覽”按鈕:

Your article will open in a separate tab where you can see how your code will be rendered once your article is published. Take some time to check on the styling and functionality of your multiple choice quiz.

您的文章將在單獨的標簽中打開,您可以在其中看到發布文章后代碼的呈現方式。 花一些時間檢查選擇題的樣式和功能。

Boilerplate code for the multiple choice quiz is available in the next section. All you need to do is paste it into your own article and change the question and answers.

下一部分提供了用于多項選擇測驗的樣板代碼。 您需要做的就是將其粘貼到您自己的文章中,然后更改問題和答案。

多項選擇測驗如何運作 (How the multiple choice quiz works)

You can add as many different questions as you want. However, while your article might have multiple quizzes, they're all contained within a single HTML body behind the scenes. Each question element starts with the following code:

您可以根據需要添加任意多個不同的問題。 但是,盡管您的文章可能有多個測驗,但它們都包含在幕后的單個HTML正文中 。 每個問題元素均以以下代碼開頭:

<div style='transform: scale(0.65); position: relative; top: -100px;'><h3>WRITE YOUR QUESTION HERE</h3><p>Choose 1 answer</p><hr />

Each of the following div elements contains a possible answer:

以下每個div元素均包含一個可能的答案:

...<div id='block-11' style='padding: 10px;'><label for='option-11' style=' padding: 5px; font-size: 2.5rem;'><input type='radio' name='option' value='6/24' id='option-11' style='transform: scale(1.6); margin-right: 10px; vertical-align: middle; margin-top: -2px;' />ANSWER 1</label><span id='result-11'></span></div><hr /><div id='block-12' style='padding: 10px;'><label for='option-12' style=' padding: 5px; font-size: 2.5rem;'><input type='radio' name='option' value='6' id='option-12' style='transform: scale(1.6); margin-right: 10px; vertical-align: middle; margin-top: -2px;' />ANSWER 2</label><span id='result-12'></span></div><hr />...

At the time of writing, Ghost's embedded code editor does not support template literals, so some things have to be hard coded.

在撰寫本文時,Ghost的嵌入式代碼編輯器不支持模板文字,因此某些事情必須進行硬編碼。

Remember that all the questions are essentially loaded together behind the scenes, so the two digit numbers in each id represent the following:

請記住,所有問題實際上都是在后臺加載的,因此每個id的兩位數字表示以下內容:

  • The first digit indicates the order of the multiple choice question in the article (1 is question one, 2 is question two, and so on)

    一位數字表示文章中多項選擇題的順序(1是問題一,2是問題二,依此類推)

  • The second digit indicates the order of each possible answer within its question block (1 is answer choice one, 2 is answer choice two, etc.)

    第二個數字指示其問題塊中每個可能答案的順序(1是答案選擇一,2是答案選擇二,依此類推)

For example, block-12 represents question 1/answer choice 2, while block-43 is question 4/answer choice 3.

例如, block-12代表問題 1 /答案選擇2 ,而block-43 問題4 /答案選擇3

This indexing convention is necessary for different question blocks to function independently from each other.

該索引約定對于不同的問題塊彼此獨立運行是必需的。

Similar logic applies to the function names responsible for interactivity. The code that handles user interaction is placed within <script> tags and consists of two parts. First part is the function that evaluates answers and displays results:

類似的邏輯適用于負責交互的功能名稱。 處理用戶交互的代碼位于<script>標記內,并且由兩部分組成。 第一部分是評估答案并顯示結果的功能:

function displayAnswer1() {if (document.getElementById('option-11').checked) {document.getElementById('block-11').style.border = '3px solid limegreen'document.getElementById('result-11').style.color = 'limegreen'document.getElementById('result-11').innerHTML = 'Correct!'}if (document.getElementById('option-12').checked) {document.getElementById('block-12').style.border = '3px solid red'document.getElementById('result-12').style.color = 'red'document.getElementById('result-12').innerHTML = 'Incorrect!'showCorrectAnswer1()}if (document.getElementById('option-13').checked) {document.getElementById('block-13').style.border = '3px solid red'document.getElementById('result-13').style.color = 'red'document.getElementById('result-13').innerHTML = 'Incorrect!'showCorrectAnswer1()}if (document.getElementById('option-14').checked) {document.getElementById('block-14').style.border = '3px solid red'document.getElementById('result-14').style.color = 'red'document.getElementById('result-14').innerHTML = 'Incorrect!'showCorrectAnswer1()}}

Like the name suggests, the displayAnswer1 function handles the first question within an article. If there's a third question in your article, displayAnswer3 will handle it.

顧名思義, displayAnswer1函數處理文章中的第一個問題。 如果您的文章中還有第三個問題,則displayAnswer3將處理該問題。

In the example above, option-11 is the correct answer, and the styling in the first if block is updated to show the right answer was selected. If any of the other incorrect answers are selected, the styling is updated to reflect that.

在上面的示例中, option-11是正確的答案,并且第一個if塊中的樣式已更新為顯示了正確的答案。 如果選擇了其他任何不正確的答案,則會更新樣式以反映出來。

Feel free to play with the displayAnswer_ functions in your own article. Just remember to attach the appropriate styling to the correct and incorrect answers.

隨意在您自己的文章中使用displayAnswer_函數。 只要記住將正確的樣式附加到正確和不正確的答案即可。

Here's the second part of the code that handles user interaction:

這是處理用戶交互的代碼的第二部分:

function showCorrectAnswer1() {let showAnswer1 = document.createElement('p')showAnswer1.innerHTML = 'Show Corrent Answer'showAnswer1.style.position = 'relative'showAnswer1.style.top = '-180px'showAnswer1.style.fontSize = '1.75rem'document.getElementById('showanswer1').appendChild(showAnswer1)showAnswer1.addEventListener('click', () => {document.getElementById('block-11').style.border = '3px solid limegreen'document.getElementById('result-11').style.color = 'limegreen'document.getElementById('result-11').innerHTML = 'Correct!'document.getElementById('showanswer1').removeChild(showAnswer1)})}

This function is called showCorrectAnswer1 because it handles the first multiple choice question in the article. You'll have to add showCorrectAnswer2, showCorrectAnswer3, and more if your article has more than one question.

該函數稱為showCorrectAnswer1因為它處理了文章中的第一個多選問題。 如果您的文章有多個問題,則必須添加showCorrectAnswer2showCorrectAnswer3以及更多內容。

Please play around with the styling and dimensions used throughout the code, and customize it to your taste. Also, I'm sure there are other ways to implement multiple choice quizzes, but this is mine, and I'm happy to share it with you.

請試用整個代碼中使用的樣式和尺寸,并根據自己的喜好對其進行自定義。 另外,我敢肯定還有其他方法可以實施多項選擇測驗,但這是我的,很高興與您分享。

Here's the full code and a working example:

這是完整的代碼和一個有效的示例:

<div style='transform: scale(0.65); position: relative; top: -100px;'><h3>What fraction of a day is 6 hours?</h3><p>Choose 1 answer</p><hr /><div id='block-11' style='padding: 10px;'><label for='option-11' style=' padding: 5px; font-size: 2.5rem;'><input type='radio' name='option' value='6/24' id='option-11' style='transform: scale(1.6); margin-right: 10px; vertical-align: middle; margin-top: -2px;' />6/24</label><span id='result-11'></span></div><hr /><div id='block-12' style='padding: 10px;'><label for='option-12' style=' padding: 5px; font-size: 2.5rem;'><input type='radio' name='option' value='6' id='option-12' style='transform: scale(1.6); margin-right: 10px; vertical-align: middle; margin-top: -2px;' />6</label><span id='result-12'></span></div><hr /><div id='block-13' style='padding: 10px;'><label for='option-13' style=' padding: 5px; font-size: 2.5rem;'><input type='radio' name='option' value='1/3' id='option-13' style='transform: scale(1.6); margin-right: 10px; vertical-align: middle; margin-top: -2px;' />1/3</label><span id='result-13'></span></div><hr /><div id='block-14' style='padding: 10px;'><label for='option-14' style=' padding: 5px; font-size: 2.5rem;'><input type='radio' name='option' value='1/6' id='option-14' style='transform: scale(1.6); margin-right: 10px; vertical-align: middle; margin-top: -2px;' />1/6</label><span id='result-14'></span></div><hr /><button type='button' onclick='displayAnswer1()' style='width: 100px; height: 40px; border-radius: 3px; background-color: lightblue; font-weight: 700;'>Submit</button>
</div>
<a id='showanswer1'></a>
<script>//    The function evaluates the answer and displays resultfunction displayAnswer1() {if (document.getElementById('option-11').checked) {document.getElementById('block-11').style.border = '3px solid limegreen'document.getElementById('result-11').style.color = 'limegreen'document.getElementById('result-11').innerHTML = 'Correct!'}if (document.getElementById('option-12').checked) {document.getElementById('block-12').style.border = '3px solid red'document.getElementById('result-12').style.color = 'red'document.getElementById('result-12').innerHTML = 'Incorrect!'showCorrectAnswer1()}if (document.getElementById('option-13').checked) {document.getElementById('block-13').style.border = '3px solid red'document.getElementById('result-13').style.color = 'red'document.getElementById('result-13').innerHTML = 'Incorrect!'showCorrectAnswer1()}if (document.getElementById('option-14').checked) {document.getElementById('block-14').style.border = '3px solid red'document.getElementById('result-14').style.color = 'red'document.getElementById('result-14').innerHTML = 'Incorrect!'showCorrectAnswer1()}}// the functon displays the link to the correct answerfunction showCorrectAnswer1() {let showAnswer1 = document.createElement('p')showAnswer1.innerHTML = 'Show Corrent Answer'showAnswer1.style.position = 'relative'showAnswer1.style.top = '-180px'showAnswer1.style.fontSize = '1.75rem'document.getElementById('showanswer1').appendChild(showAnswer1)showAnswer1.addEventListener('click', () => {document.getElementById('block-11').style.border = '3px solid limegreen'document.getElementById('result-11').style.color = 'limegreen'document.getElementById('result-11').innerHTML = 'Correct!'document.getElementById('showanswer1').removeChild(showAnswer1)})}
</script>

一天的哪一部分是6個小時? (What fraction of a day is 6 hours?)

Choose 1 answer

選擇1個答案











You can also find the complete boilerplate code here on GitHub.

您還可以在GitHub上找到完整的樣板代碼。

翻譯自: https://www.freecodecamp.org/news/multiple-choice-quiz-template/

文章中嵌入代碼塊

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390368.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390368.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390368.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

mysql免安裝版配置

1.官網下載https://dev.mysql.com/downloads/mysql/ 2.將下載好的壓縮包mysql-5.7.20-winx64.zip解壓。 3.mysql解壓后&#xff0c;設置.ini文件&#xff0c;在加壓后的路徑中加一個my.ini文件 配置如下內容&#xff1a; # 設置mysql客戶端默認字符集 default-character-setutf…

各種IE(IE6-IE10)兼容問題一行代碼搞定

x-ua-compatible 用來指定IE瀏覽器解析編譯頁面的model x-ua-compatible 頭標簽大小寫不敏感&#xff0c;必須用在 head 中&#xff0c;必須在除 title 外的其他 meta 之前使用。 1、使用一行代碼來指定瀏覽器使用特定的文檔模式。 <meta http-equiv"x-ua-compatible&q…

802. 找到最終的安全狀態

在有向圖中&#xff0c;以某個節點為起始節點&#xff0c;從該點出發&#xff0c;每一步沿著圖中的一條有向邊行走。如果到達的節點是終點&#xff08;即它沒有連出的有向邊&#xff09;&#xff0c;則停止。 對于一個起始節點&#xff0c;如果從該節點出發&#xff0c;無論每…

元類型與類型的區別

元類型是指所有類型的類型。 元類型只能類型出現在類型標示位&#xff1b; 類型即能作為類型存在&#xff0c;出現在類型標示位&#xff1b; 也能作為變量存在&#xff0c;出現在元類型的變量位。 http://www.swift51.com/swift2.0/chapter3/03_Types.html#type_inheritance_cl…

css 動畫使用_如何在CSS中使用動畫

css 動畫使用使用CSS動畫 (Using CSS Animations) CSS animations add beauty to the webpages and make transitions from one CSS style to the other beautiful.CSS動畫可以使網頁更加美觀&#xff0c;并可以從一種CSS樣式過渡到另一種CSS樣式。 To create a CSS animation…

第01章—快速構建

spring boot 系列學習記錄&#xff1a;http://www.cnblogs.com/jinxiaohang/p/8111057.html 碼云源碼地址&#xff1a;https://gitee.com/jinxiaohang/springboot 一、Spring Initializr 使用教程 &#xff08;IntelliJ IDEA&#xff09; 具體步驟&#xff1a; 1、打開IDEA &am…

看板和scrum_看板VS Scrum-如何變得敏捷

看板和scrumScrum and Kanban are the two most popular project management techniques today in business. As a developer, I think its important to understand these processes as you will likely be heavily involved in them if you are part of a team. By understan…

JS之Promise

開胃菜&#xff0c;先做如下思考&#xff1a; Promise 有幾種狀態&#xff1f;Promise 狀態之間可以轉化嗎&#xff1f;Promise 中的異常可以被 try...catch 捕獲嗎&#xff1f;Promise前世 callback hell 大家都知道JS是異步操作&#xff08;執行&#xff09;的&#xff0c;在…

魚眼鏡頭的distortion校正【matlab】

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 作者&#xff1a;WWC %%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% 功能&#xff1a;畸變矯正 clc; clear; close all; %% 讀取圖像 Aimread(D:\文件及下載相關\圖片\distortion2.jpg)…

web后端開發學習路線_學習后端Web開發的最佳方法

web后端開發學習路線My previous article described how you can get into frontend development. It also discussed how the front end can be a place filled with landmines – step in the wrong place and youll be overwhelmed by the many frameworks of the JavaScrip…

C# 使用WinApi操作剪切板Clipboard

前言&#xff1a; 最近正好寫一個程序&#xff0c;需要操作剪切板 功能很簡單&#xff0c;只需要從剪切板內讀取字符串&#xff0c;然后清空剪切板&#xff0c;然后再把字符串導入剪切板 我想當然的使用我最拿手的C#來完成這項工作&#xff0c;原因無他&#xff0c;因為.Net框架…

聊聊spring cloud gateway的XForwardedHeadersFilter

序 本文主要研究spring cloud gateway的XForwardedHeadersFilter GatewayAutoConfiguration spring-cloud-gateway-core-2.0.0.RC1-sources.jar!/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java Configuration ConditionalOnProperty(name "sp…

node緩沖區_Node.js緩沖區介紹

node緩沖區什么是緩沖液&#xff1f; (What are Buffers?) Binary is simply a set or a collection of 1 and 0. Each number in a binary, each 1 and 0 in a set are called a bit. Computer converts the data to this binary format to store and perform operations. Fo…

專訪趙加雨:WebRTC在網易云信的落地

去年的這個時候&#xff0c;在市面上公開表示使用WebRTC的公司還沒幾家&#xff0c;但2018年以來&#xff0c;宣布采用或支持WebRTC的公司已經越來越多。實時音視頻提供商網易云信也在自研的NRTC中集成了WebRTC。在他們眼里&#xff0c;2017年是WebRTC的轉折之年&#xff0c;而…

html/css雜題

1、css選擇器&#xff1a;詳細&#xff08;http://www.ruanyifeng.com/blog/2009/03/css_selectors.html&#xff09; 派生選擇器&#xff1a;按標簽 類別選擇器&#xff1a;按class ID選擇器&#xff1a;按ID 通用選擇器&#xff1a;* 匹配所有 屬性選擇器&#xff1a;按屬性&…

黑客馬拉松 招募_我如何贏得第一次黑客馬拉松-研究,設計和編碼的2個狂野日子

黑客馬拉松 招募I had no coding or engineering background. I studied biology in college, with no clue about what to do with my degree. 我沒有編碼或工程背景。 我在大學學習生物學&#xff0c;但不知道如何處理我的學位。 My first jobs were making cold calls in s…

1、Linux命令隨筆

1 Linux命令總結2 3 man 命令幫助;4 help 命令的幫助&#xff08;bash的內置命令&#xff09;;5 ls list,查看目錄列表;6 -ld&#xff1a;查看目錄權限;7 -l:(long)長格式顯示屬性;8 -F:給不同的文件類型結尾加標識9 -p:給目錄加斜線10 …

1137. 第 N 個泰波那契數

泰波那契序列 Tn 定義如下&#xff1a; T0 0, T1 1, T2 1, 且在 n > 0 的條件下 Tn3 Tn Tn1 Tn2 給你整數 n&#xff0c;請返回第 n 個泰波那契數 Tn 的值。 示例 1&#xff1a; 輸入&#xff1a;n 4 輸出&#xff1a;4 解釋&#xff1a; T_3 0 1 1 2 T_4 1…

web圖像_Web圖像優化的基本介紹

web圖像Images are an essential ingredient of most websites. The visual quality of pictures has a direct impact on the brand image and the message those images convey. And the weight of images usually accounts for a 40-60% of the data transferred on the web…

ElasticSearch客戶端注解使用介紹

The best elasticsearch highlevel java rest api-----bboss 1.ElasticSearch客戶端bboss提供了一系列注解 ESId 用于標識實體對象中作為docid的屬性&#xff0c;該注解只有一個persistent 布爾值屬性&#xff0c;用于控制被本注解標注的字段屬性是否作為普通文檔屬性保存&am…