{"id":286,"date":"2026-03-19T22:32:28","date_gmt":"2026-03-19T14:32:28","guid":{"rendered":"https:\/\/www.resilence.cn\/?p=286"},"modified":"2026-03-19T22:32:28","modified_gmt":"2026-03-19T14:32:28","slug":"day-21-%e9%a1%b9%e7%9b%ae3-%e7%8c%9c%e6%95%b0%e5%ad%97%e6%b8%b8%e6%88%8f","status":"publish","type":"post","link":"https:\/\/www.resilence.cn\/?p=286","title":{"rendered":"Day-21-\u9879\u76ee3-\u731c\u6570\u5b57\u6e38\u620f"},"content":{"rendered":"<h1>Day 21: \u9879\u76ee3-\u731c\u6570\u5b57\u6e38\u620f<\/h1>\n<blockquote>\n<p>\ud83c\udfaf <strong>Day 21 &#8211; \u731c\u6570\u5b57\u6e38\u620f<\/strong><br \/>\n\ud83d\udcc2 \u5206\u7c7b: 09-\u9879\u76ee\u5b9e\u6218<br \/>\n\ud83d\udd25 \u96be\u5ea6: \u2b50\u2b50\u2b50\u2606\u2606<\/p>\n<\/blockquote>\n<hr>\n<h2>\ud83c\udfaf \u5b66\u4e60\u76ee\u6807<\/h2>\n<ul>\n<li>\u2705 \u638c\u63e1 Math.random() \u548c\u968f\u673a\u6570\u751f\u6210<\/li>\n<li>\u2705 \u5b66\u4f1a\u8868\u5355\u9a8c\u8bc1\u548c\u7528\u6237\u8f93\u5165\u5904\u7406<\/li>\n<li>\u2705 \u7406\u89e3\u6e38\u620f\u5faa\u73af\u548c\u72b6\u6001\u7ba1\u7406<\/li>\n<li>\u2705 \u638c\u63e1\u4e8b\u4ef6\u76d1\u542c\u548c\u4ea4\u4e92\u903b\u8f91<\/li>\n<li>\u2705 \u5b66\u4f1a\u4f7f\u7528 CSS \u52a8\u753b\u589e\u5f3a\u4f53\u9a8c<\/li>\n<\/ul>\n<hr>\n<h2>\ud83d\udca1 \u9879\u76ee\u6982\u8ff0<\/h2>\n<h3>\u9879\u76ee\u7b80\u4ecb<\/h3>\n<p><strong>\u731c\u6570\u5b57\u6e38\u620f<\/strong>\u662f\u5b66\u4e60\u4ea4\u4e92\u5f0f\u7f16\u7a0b\u7684\u7ecf\u5178\u9879\u76ee\uff0c\u5b83\u5305\u542b\uff1a<\/p>\n<ul>\n<li>\ud83c\udfb2 <strong>\u968f\u673a\u6570\u751f\u6210<\/strong>\uff1aMath.random() \u7684\u5b9e\u9645\u5e94\u7528<\/li>\n<li>\ud83c\udfae <strong>\u6e38\u620f\u5faa\u73af<\/strong>\uff1a\u5f00\u59cb \u2192 \u731c\u6d4b \u2192 \u53cd\u9988 \u2192 \u7ee7\u7eed<\/li>\n<li>\ud83c\udfc6 <strong>\u80dc\u8d1f\u5224\u5b9a<\/strong>\uff1a\u6bd4\u8f83\u731c\u6d4b\u4e0e\u76ee\u6807\u6570\u5b57<\/li>\n<li>\ud83d\udcca <strong>\u7edf\u8ba1\u8ffd\u8e2a<\/strong>\uff1a\u8bb0\u5f55\u731c\u6d4b\u6b21\u6570\u548c\u6700\u4f73\u6210\u7ee9<\/li>\n<li>\ud83c\udfa8 <strong>UI \u53cd\u9988<\/strong>\uff1a\u89c6\u89c9\u63d0\u793a\u548c\u52a8\u753b\u6548\u679c<\/li>\n<\/ul>\n<h3>\u6838\u5fc3\u529f\u80fd<\/h3>\n<ul>\n<li>[ ] \u751f\u6210 1-100 \u7684\u968f\u673a\u6570<\/li>\n<li>[ ] \u63a5\u53d7\u7528\u6237\u8f93\u5165\u5e76\u9a8c\u8bc1<\/li>\n<li>[ ] \u5224\u65ad\u5927\u5c0f\u5e76\u7ed9\u51fa\u63d0\u793a<\/li>\n<li>[ ] \u8bb0\u5f55\u731c\u6d4b\u6b21\u6570<\/li>\n<li>[ ] \u91cd\u65b0\u5f00\u59cb\u6e38\u620f<\/li>\n<li>[ ] \u5386\u53f2\u6700\u4f73\u6210\u7ee9<\/li>\n<\/ul>\n<h3>\u6280\u672f\u91cd\u70b9<\/h3>\n<ul>\n<li><strong>\u968f\u673a\u6570<\/strong>: Math.random()\u3001Math.floor()<\/li>\n<li><strong>DOM \u64cd\u4f5c<\/strong>: \u8868\u5355\u3001\u6309\u94ae\u3001\u6587\u672c<\/li>\n<li><strong>\u4e8b\u4ef6\u5904\u7406<\/strong>: submit\u3001click\u3001keypress<\/li>\n<li><strong>\u72b6\u6001\u7ba1\u7406<\/strong>: \u6e38\u620f\u72b6\u6001\u3001\u5386\u53f2\u8bb0\u5f55<\/li>\n<li><strong>CSS \u52a8\u753b<\/strong>: \u8fc7\u6e21\u6548\u679c\u3001\u89c6\u89c9\u53cd\u9988<\/li>\n<\/ul>\n<hr>\n<h2>\ud83d\udcdd \u9879\u76ee\u7ed3\u6784<\/h2>\n<pre><code>guess-game\/\n\u251c\u2500\u2500 index.html          # \u4e3b\u9875\u9762\n\u251c\u2500\u2500 style.css           # \u6837\u5f0f\u6587\u4ef6\n\u2514\u2500\u2500 script.js           # JavaScript\u903b\u8f91\n<\/code><\/pre>\n<hr>\n<h2>\ud83c\udfae \u5b8c\u6574\u4ee3\u7801<\/h2>\n<h3>1. HTML (index.html)<\/h3>\n<pre><code class=\"language-html\">&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;zh-CN&quot;&gt;\n&lt;head&gt;\n    &lt;meta charset=&quot;UTF-8&quot;&gt;\n    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n    &lt;title&gt;\u731c\u6570\u5b57\u6e38\u620f&lt;\/title&gt;\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;div class=&quot;container&quot;&gt;\n        &lt;header&gt;\n            &lt;h1&gt;\ud83c\udfb2 \u731c\u6570\u5b57\u6e38\u620f&lt;\/h1&gt;\n            &lt;p class=&quot;subtitle&quot;&gt;\u6211\u6709\u4e00\u4e2a 1-100 \u4e4b\u95f4\u7684\u6570\u5b57\uff0c\u4f60\u80fd\u731c\u5230\u5417\uff1f&lt;\/p&gt;\n        &lt;\/header&gt;\n\n        &lt;!-- \u6e38\u620f\u4fe1\u606f --&gt;\n        &lt;div class=&quot;game-info&quot;&gt;\n            &lt;div class=&quot;info-item&quot;&gt;\n                &lt;span class=&quot;label&quot;&gt;\u5c1d\u8bd5\u6b21\u6570&lt;\/span&gt;\n                &lt;span class=&quot;value&quot; id=&quot;guessCount&quot;&gt;0&lt;\/span&gt;\n            &lt;\/div&gt;\n            &lt;div class=&quot;info-item&quot;&gt;\n                &lt;span class=&quot;label&quot;&gt;\u5386\u53f2\u6700\u4f73&lt;\/span&gt;\n                &lt;span class=&quot;value&quot; id=&quot;bestScore&quot;&gt;-&lt;\/span&gt;\n            &lt;\/div&gt;\n        &lt;\/div&gt;\n\n        &lt;!-- \u6e38\u620f\u533a\u57df --&gt;\n        &lt;div class=&quot;game-area&quot;&gt;\n            &lt;!-- \u8f93\u5165\u533a\u57df --&gt;\n            &lt;div class=&quot;input-section&quot;&gt;\n                &lt;label for=&quot;guessInput&quot;&gt;\u8f93\u5165\u4f60\u7684\u731c\u6d4b (1-100)&lt;\/label&gt;\n                &lt;div class=&quot;input-group&quot;&gt;\n                    &lt;input \n                        type=&quot;number&quot; \n                        id=&quot;guessInput&quot; \n                        min=&quot;1&quot; \n                        max=&quot;100&quot; \n                        placeholder=&quot;\u8f93\u5165\u6570\u5b57...&quot;\n                        autocomplete=&quot;off&quot;\n                    &gt;\n                    &lt;button id=&quot;submitBtn&quot; class=&quot;btn btn-primary&quot;&gt;\u731c\uff01&lt;\/button&gt;\n                &lt;\/div&gt;\n                &lt;p class=&quot;hint&quot; id=&quot;inputHint&quot;&gt;&lt;\/p&gt;\n            &lt;\/div&gt;\n\n            &lt;!-- \u53cd\u9988\u533a\u57df --&gt;\n            &lt;div class=&quot;feedback-section&quot; id=&quot;feedback&quot;&gt;\n                &lt;div class=&quot;feedback-icon&quot; id=&quot;feedbackIcon&quot;&gt;\u2753&lt;\/div&gt;\n                &lt;div class=&quot;feedback-message&quot; id=&quot;feedbackMessage&quot;&gt;\n                    \u5f00\u59cb\u6e38\u620f\u5427\uff01\u8f93\u5165\u4f60\u7684\u731c\u6d4b\n                &lt;\/div&gt;\n                &lt;div class=&quot;feedback-detail&quot; id=&quot;feedbackDetail&quot;&gt;&lt;\/div&gt;\n            &lt;\/div&gt;\n\n            &lt;!-- \u5386\u53f2\u8bb0\u5f55 --&gt;\n            &lt;div class=&quot;history-section&quot;&gt;\n                &lt;h3&gt;\u731c\u6d4b\u5386\u53f2&lt;\/h3&gt;\n                &lt;div class=&quot;history-list&quot; id=&quot;historyList&quot;&gt;\n                    &lt;p class=&quot;empty&quot;&gt;\u8fd8\u6ca1\u6709\u731c\u6d4b\u8bb0\u5f55&lt;\/p&gt;\n                &lt;\/div&gt;\n            &lt;\/div&gt;\n\n            &lt;!-- \u91cd\u65b0\u5f00\u59cb --&gt;\n            &lt;button id=&quot;restartBtn&quot; class=&quot;btn btn-secondary&quot; style=&quot;display: none;&quot;&gt;\n                \ud83d\udd04 \u91cd\u65b0\u5f00\u59cb\n            &lt;\/button&gt;\n        &lt;\/div&gt;\n    &lt;\/div&gt;\n\n    &lt;script src=&quot;script.js&quot;&gt;&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n<h3>2. CSS (style.css)<\/h3>\n<pre><code class=\"language-css\">\/* \u5168\u5c40\u6837\u5f0f *\/\n* {\n    margin: 0;\n    padding: 0;\n    box-sizing: border-box;\n}\n\nbody {\n    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;\n    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n    min-height: 100vh;\n    display: flex;\n    justify-content: center;\n    align-items: center;\n    padding: 20px;\n}\n\n\/* \u5bb9\u5668 *\/\n.container {\n    background: white;\n    border-radius: 20px;\n    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);\n    max-width: 500px;\n    width: 100%;\n    padding: 30px;\n    animation: fadeIn 0.5s ease;\n}\n\n@keyframes fadeIn {\n    from {\n        opacity: 0;\n        transform: translateY(-20px);\n    }\n    to {\n        opacity: 1;\n        transform: translateY(0);\n    }\n}\n\n\/* \u5934\u90e8 *\/\nheader {\n    text-align: center;\n    margin-bottom: 30px;\n}\n\nheader h1 {\n    color: #333;\n    font-size: 32px;\n    margin-bottom: 10px;\n}\n\n.subtitle {\n    color: #666;\n    font-size: 14px;\n}\n\n\/* \u6e38\u620f\u4fe1\u606f *\/\n.game-info {\n    display: flex;\n    justify-content: space-around;\n    background: #f7f7f7;\n    border-radius: 12px;\n    padding: 15px;\n    margin-bottom: 30px;\n}\n\n.info-item {\n    text-align: center;\n}\n\n.info-item .label {\n    display: block;\n    color: #666;\n    font-size: 12px;\n    margin-bottom: 5px;\n}\n\n.info-item .value {\n    display: block;\n    color: #667eea;\n    font-size: 24px;\n    font-weight: bold;\n}\n\n\/* \u6e38\u620f\u533a\u57df *\/\n.game-area {\n    margin-top: 20px;\n}\n\n\/* \u8f93\u5165\u533a\u57df *\/\n.input-section {\n    margin-bottom: 20px;\n}\n\n.input-section label {\n    display: block;\n    color: #333;\n    font-weight: 600;\n    margin-bottom: 10px;\n}\n\n.input-group {\n    display: flex;\n    gap: 10px;\n}\n\n#guessInput {\n    flex: 1;\n    padding: 15px;\n    border: 2px solid #e0e0e0;\n    border-radius: 10px;\n    font-size: 18px;\n    text-align: center;\n    transition: border-color 0.3s;\n}\n\n#guessInput:focus {\n    outline: none;\n    border-color: #667eea;\n}\n\n.btn {\n    padding: 15px 30px;\n    border: none;\n    border-radius: 10px;\n    font-size: 16px;\n    font-weight: 600;\n    cursor: pointer;\n    transition: all 0.3s;\n}\n\n.btn-primary {\n    background: #667eea;\n    color: white;\n}\n\n.btn-primary:hover {\n    background: #5568d3;\n    transform: scale(1.05);\n}\n\n.btn-secondary {\n    background: #f7f7f7;\n    color: #333;\n    width: 100%;\n    margin-top: 20px;\n}\n\n.btn-secondary:hover {\n    background: #e0e0e0;\n}\n\n.hint {\n    color: #999;\n    font-size: 12px;\n    margin-top: 8px;\n    min-height: 18px;\n}\n\n.hint.error {\n    color: #f56565;\n}\n\n.hint.success {\n    color: #48bb78;\n}\n\n\/* \u53cd\u9988\u533a\u57df *\/\n.feedback-section {\n    background: #f7f7f7;\n    border-radius: 12px;\n    padding: 20px;\n    text-align: center;\n    margin-bottom: 20px;\n    transition: all 0.3s;\n}\n\n.feedback-section.too-high {\n    background: #fed7d7;\n    border: 2px solid #fc8181;\n}\n\n.feedback-section.too-low {\n    background: #bee3f8;\n    border: 2px solid #63b3ed;\n}\n\n.feedback-section.correct {\n    background: #c6f6d5;\n    border: 2px solid #48bb78;\n    animation: celebrate 0.5s ease;\n}\n\n@keyframes celebrate {\n    0%, 100% { transform: scale(1); }\n    50% { transform: scale(1.05); }\n}\n\n.feedback-icon {\n    font-size: 48px;\n    margin-bottom: 10px;\n}\n\n.feedback-message {\n    font-size: 20px;\n    font-weight: bold;\n    color: #333;\n    margin-bottom: 10px;\n}\n\n.feedback-detail {\n    font-size: 14px;\n    color: #666;\n}\n\n\/* \u5386\u53f2\u8bb0\u5f55 *\/\n.history-section {\n    margin-bottom: 20px;\n}\n\n.history-section h3 {\n    font-size: 16px;\n    color: #333;\n    margin-bottom: 10px;\n}\n\n.history-list {\n    background: #f7f7f7;\n    border-radius: 10px;\n    padding: 15px;\n    max-height: 200px;\n    overflow-y: auto;\n}\n\n.history-list .empty {\n    color: #999;\n    text-align: center;\n    font-size: 14px;\n}\n\n.history-item {\n    display: flex;\n    justify-content: space-between;\n    align-items: center;\n    padding: 8px;\n    border-bottom: 1px solid #e0e0e0;\n    animation: slideIn 0.3s ease;\n}\n\n@keyframes slideIn {\n    from {\n        opacity: 0;\n        transform: translateX(-10px);\n    }\n    to {\n        opacity: 1;\n        transform: translateX(0);\n    }\n}\n\n.history-item:last-child {\n    border-bottom: none;\n}\n\n.history-number {\n    font-weight: bold;\n    color: #333;\n}\n\n.history-arrow {\n    font-size: 12px;\n    margin: 0 10px;\n}\n\n.history-arrow.high {\n    color: #fc8181;\n}\n\n.history-arrow.low {\n    color: #63b3ed;\n}\n\n\/* \u54cd\u5e94\u5f0f *\/\n@media (max-width: 480px) {\n    .container {\n        padding: 20px;\n    }\n    \n    header h1 {\n        font-size: 24px;\n    }\n    \n    .input-group {\n        flex-direction: column;\n    }\n    \n    .btn-primary {\n        width: 100%;\n    }\n}\n<\/code><\/pre>\n<h3>3. JavaScript (script.js)<\/h3>\n<pre><code class=\"language-javascript\">\/\/ ========== \u6e38\u620f\u72b6\u6001 ==========\nclass GuessGame {\n    constructor() {\n        this.targetNumber = this.generateRandomNumber();\n        this.guessCount = 0;\n        this.guessHistory = [];\n        this.gameOver = false;\n        this.bestScore = this.loadBestScore();\n        \n        this.initializeElements();\n        this.attachEventListeners();\n        this.updateDisplay();\n        this.loadBestScore();\n    }\n\n    \/\/ \u521d\u59cb\u5316 DOM \u5143\u7d20\n    initializeElements() {\n        this.elements = {\n            guessInput: document.getElementById('guessInput'),\n            submitBtn: document.getElementById('submitBtn'),\n            restartBtn: document.getElementById('restartBtn'),\n            guessCount: document.getElementById('guessCount'),\n            bestScore: document.getElementById('bestScore'),\n            feedback: document.getElementById('feedback'),\n            feedbackIcon: document.getElementById('feedbackIcon'),\n            feedbackMessage: document.getElementById('feedbackMessage'),\n            feedbackDetail: document.getElementById('feedbackDetail'),\n            historyList: document.getElementById('historyList'),\n            inputHint: document.getElementById('inputHint')\n        };\n    }\n\n    \/\/ \u9644\u52a0\u4e8b\u4ef6\u76d1\u542c\u5668\n    attachEventListeners() {\n        \/\/ \u63d0\u4ea4\u6309\u94ae\n        this.elements.submitBtn.addEventListener('click', () =&gt; {\n            this.handleGuess();\n        });\n\n        \/\/ \u56de\u8f66\u952e\u63d0\u4ea4\n        this.elements.guessInput.addEventListener('keypress', (e) =&gt; {\n            if (e.key === 'Enter') {\n                this.handleGuess();\n            }\n        });\n\n        \/\/ \u8f93\u5165\u9a8c\u8bc1\n        this.elements.guessInput.addEventListener('input', () =&gt; {\n            this.validateInput();\n        });\n\n        \/\/ \u91cd\u65b0\u5f00\u59cb\n        this.elements.restartBtn.addEventListener('click', () =&gt; {\n            this.restart();\n        });\n    }\n\n    \/\/ \u751f\u6210\u968f\u673a\u6570 (1-100)\n    generateRandomNumber() {\n        return Math.floor(Math.random() * 100) + 1;\n    }\n\n    \/\/ \u9a8c\u8bc1\u8f93\u5165\n    validateInput() {\n        const value = this.elements.guessInput.value;\n        const hint = this.elements.inputHint;\n        \n        if (value === '') {\n            hint.textContent = '';\n            hint.className = 'hint';\n            return false;\n        }\n\n        const num = parseInt(value);\n        \n        if (isNaN(num)) {\n            hint.textContent = '\u8bf7\u8f93\u5165\u6709\u6548\u7684\u6570\u5b57';\n            hint.className = 'hint error';\n            return false;\n        }\n\n        if (num &lt; 1 || num &gt; 100) {\n            hint.textContent = '\u6570\u5b57\u5fc5\u987b\u5728 1-100 \u4e4b\u95f4';\n            hint.className = 'hint error';\n            return false;\n        }\n\n        hint.textContent = '\u2713 \u6709\u6548';\n        hint.className = 'hint success';\n        return true;\n    }\n\n    \/\/ \u5904\u7406\u731c\u6d4b\n    handleGuess() {\n        if (this.gameOver) {\n            return;\n        }\n\n        if (!this.validateInput()) {\n            this.shakeInput();\n            return;\n        }\n\n        const guess = parseInt(this.elements.guessInput.value);\n        this.guessCount++;\n        \n        \/\/ \u6dfb\u52a0\u5230\u5386\u53f2\n        this.guessHistory.push(guess);\n        \n        \/\/ \u5224\u65ad\u7ed3\u679c\n        if (guess === this.targetNumber) {\n            this.handleCorrectGuess(guess);\n        } else if (guess &gt; this.targetNumber) {\n            this.handleTooHigh(guess);\n        } else {\n            this.handleTooLow(guess);\n        }\n        \n        \/\/ \u66f4\u65b0\u663e\u793a\n        this.updateDisplay();\n        this.addToHistory(guess, guess &gt; this.targetNumber ? 'high' : 'low');\n        \n        \/\/ \u6e05\u7a7a\u8f93\u5165\u5e76\u805a\u7126\n        if (!this.gameOver) {\n            this.elements.guessInput.value = '';\n            this.elements.guessInput.focus();\n        }\n    }\n\n    \/\/ \u731c\u5bf9\u4e86\n    handleCorrectGuess(guess) {\n        this.gameOver = true;\n        \n        \/\/ \u66f4\u65b0\u6700\u4f73\u6210\u7ee9\n        if (this.bestScore === null || this.guessCount &lt; this.bestScore) {\n            this.bestScore = this.guessCount;\n            this.saveBestScore();\n        }\n        \n        \/\/ \u663e\u793a\u6210\u529f\u53cd\u9988\n        this.elements.feedback.className = 'feedback-section correct';\n        this.elements.feedbackIcon.textContent = '\ud83c\udf89';\n        this.elements.feedbackMessage.textContent = '\u606d\u559c\u4f60\uff0c\u731c\u5bf9\u4e86\uff01';\n        this.elements.feedbackDetail.textContent = \n            `\u6570\u5b57\u662f ${this.targetNumber}\uff0c\u4f60\u7528\u4e86 ${this.guessCount} \u6b21\u731c\u6d4b`;\n        \n        \/\/ \u663e\u793a\u91cd\u65b0\u5f00\u59cb\u6309\u94ae\n        this.elements.restartBtn.style.display = 'block';\n        this.elements.submitBtn.disabled = true;\n        this.elements.guessInput.disabled = true;\n    }\n\n    \/\/ \u731c\u5927\u4e86\n    handleTooHigh(guess) {\n        this.elements.feedback.className = 'feedback-section too-high';\n        this.elements.feedbackIcon.textContent = '\ud83d\udcc8';\n        this.elements.feedbackMessage.textContent = '\u592a\u5927\u4e86\uff01';\n        this.elements.feedbackDetail.textContent = \n            `\u4f60\u7684\u731c\u6d4b ${guess} \u6bd4\u76ee\u6807\u6570\u5b57\u5927`;\n    }\n\n    \/\/ \u731c\u5c0f\u4e86\n    handleTooLow(guess) {\n        this.elements.feedback.className = 'feedback-section too-low';\n        this.elements.feedbackIcon.textContent = '\ud83d\udcc9';\n        this.elements.feedbackMessage.textContent = '\u592a\u5c0f\u4e86\uff01';\n        this.elements.feedbackDetail.textContent = \n            `\u4f60\u7684\u731c\u6d4b ${guess} \u6bd4\u76ee\u6807\u6570\u5b57\u5c0f`;\n    }\n\n    \/\/ \u6dfb\u52a0\u5230\u5386\u53f2\u8bb0\u5f55\n    addToHistory(guess, direction) {\n        const historyItem = document.createElement('div');\n        historyItem.className = 'history-item';\n        \n        const arrow = direction === 'high' ? '\u2193' : '\u2191';\n        const arrowClass = direction === 'high' ? 'high' : 'low';\n        \n        historyItem.innerHTML = `\n            &lt;span class=&quot;history-number&quot;&gt;#${this.guessCount}: ${guess}&lt;\/span&gt;\n            &lt;span class=&quot;history-arrow ${arrowClass}&quot;&gt;${arrow}&lt;\/span&gt;\n        `;\n        \n        \/\/ \u79fb\u9664\u7a7a\u63d0\u793a\n        const empty = this.elements.historyList.querySelector('.empty');\n        if (empty) {\n            empty.remove();\n        }\n        \n        \/\/ \u6dfb\u52a0\u5230\u5f00\u5934\n        this.elements.historyList.insertBefore(\n            historyItem,\n            this.elements.historyList.firstChild\n        );\n    }\n\n    \/\/ \u66f4\u65b0\u663e\u793a\n    updateDisplay() {\n        this.elements.guessCount.textContent = this.guessCount;\n        this.elements.bestScore.textContent = \n            this.bestScore !== null ? this.bestScore : '-';\n    }\n\n    \/\/ \u8f93\u5165\u6846\u6296\u52a8\u6548\u679c\n    shakeInput() {\n        const input = this.elements.guessInput;\n        input.style.animation = 'none';\n        input.offsetHeight;  \/\/ \u89e6\u53d1\u91cd\u7ed8\n        input.style.animation = 'shake 0.5s ease';\n    }\n\n    \/\/ \u91cd\u65b0\u5f00\u59cb\n    restart() {\n        this.targetNumber = this.generateRandomNumber();\n        this.guessCount = 0;\n        this.guessHistory = [];\n        this.gameOver = false;\n        \n        \/\/ \u91cd\u7f6e UI\n        this.elements.feedback.className = 'feedback-section';\n        this.elements.feedbackIcon.textContent = '\u2753';\n        this.elements.feedbackMessage.textContent = '\u5f00\u59cb\u6e38\u620f\u5427\uff01\u8f93\u5165\u4f60\u7684\u731c\u6d4b';\n        this.elements.feedbackDetail.textContent = '';\n        \n        this.elements.restartBtn.style.display = 'none';\n        this.elements.submitBtn.disabled = false;\n        this.elements.guessInput.disabled = false;\n        this.elements.guessInput.value = '';\n        this.elements.guessInput.focus();\n        \n        this.elements.historyList.innerHTML = '&lt;p class=&quot;empty&quot;&gt;\u8fd8\u6ca1\u6709\u731c\u6d4b\u8bb0\u5f55&lt;\/p&gt;';\n        \n        this.updateDisplay();\n    }\n\n    \/\/ \u52a0\u8f7d\u6700\u4f73\u6210\u7ee9\n    loadBestScore() {\n        const saved = localStorage.getItem('guessGameBestScore');\n        if (saved) {\n            this.bestScore = parseInt(saved);\n        }\n    }\n\n    \/\/ \u4fdd\u5b58\u6700\u4f73\u6210\u7ee9\n    saveBestScore() {\n        localStorage.setItem('guessGameBestScore', this.bestScore);\n    }\n}\n\n\/\/ \u6dfb\u52a0\u6296\u52a8\u52a8\u753b\nconst style = document.createElement('style');\nstyle.textContent = `\n    @keyframes shake {\n        0%, 100% { transform: translateX(0); }\n        10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }\n        20%, 40%, 60%, 80% { transform: translateX(5px); }\n    }\n`;\ndocument.head.appendChild(style);\n\n\/\/ \u521d\u59cb\u5316\u6e38\u620f\ndocument.addEventListener('DOMContentLoaded', () =&gt; {\n    const game = new GuessGame();\n    console.log('\ud83c\udfae \u731c\u6570\u5b57\u6e38\u620f\u5df2\u542f\u52a8\uff01');\n    console.log('\ud83d\udca1 \u63d0\u793a\uff1a\u6309\u56de\u8f66\u952e\u5feb\u901f\u63d0\u4ea4\u731c\u6d4b');\n});\n<\/code><\/pre>\n<hr>\n<h2>\ud83c\udfaf \u9879\u76ee\u4eae\u70b9<\/h2>\n<h3>1. \u5b8c\u6574\u7684\u6e38\u620f\u5faa\u73af<\/h3>\n<pre><code>\u5f00\u59cb \u2192 \u751f\u6210\u968f\u673a\u6570 \u2192 \u63a5\u53d7\u8f93\u5165 \u2192 \u5224\u65ad \u2192 \u53cd\u9988 \u2192 \u7ee7\u7eed\/\u7ed3\u675f\n<\/code><\/pre>\n<h3>2. \u72b6\u6001\u7ba1\u7406<\/h3>\n<pre><code class=\"language-javascript\">class GuessGame {\n    constructor() {\n        this.targetNumber = null;      \/\/ \u76ee\u6807\u6570\u5b57\n        this.guessCount = 0;           \/\/ \u731c\u6d4b\u6b21\u6570\n        this.guessHistory = [];        \/\/ \u5386\u53f2\u8bb0\u5f55\n        this.gameOver = false;         \/\/ \u6e38\u620f\u72b6\u6001\n        this.bestScore = null;         \/\/ \u6700\u4f73\u6210\u7ee9\n    }\n}\n<\/code><\/pre>\n<h3>3. \u7528\u6237\u8f93\u5165\u9a8c\u8bc1<\/h3>\n<pre><code class=\"language-javascript\">validateInput() {\n    \/\/ \u68c0\u67e5\u662f\u5426\u4e3a\u6570\u5b57\n    \/\/ \u68c0\u67e5\u8303\u56f4\u662f\u5426\u6709\u6548\n    \/\/ \u63d0\u4f9b\u5b9e\u65f6\u53cd\u9988\n}\n<\/code><\/pre>\n<h3>4. \u672c\u5730\u5b58\u50a8\u6700\u4f73\u6210\u7ee9<\/h3>\n<pre><code class=\"language-javascript\">\/\/ \u4fdd\u5b58\u5230 localStorage\nlocalStorage.setItem('guessGameBestScore', this.bestScore);\n\n\/\/ \u4ece localStorage \u52a0\u8f7d\nconst saved = localStorage.getItem('guessGameBestScore');\n<\/code><\/pre>\n<hr>\n<h2>\u270d\ufe0f \u7ec3\u4e60\u4efb\u52a1<\/h2>\n<h3>\u7ec3\u4e601: \u57fa\u7840\u529f\u80fd\uff0830\u5206\u949f\uff09<\/h3>\n<ul>\n<li>[ ] \u5b9e\u73b0\u968f\u673a\u6570\u751f\u6210 (1-100)<\/li>\n<li>[ ] \u5b9e\u73b0\u8f93\u5165\u9a8c\u8bc1<\/li>\n<li>[ ] \u5b9e\u73b0\u5927\u5c0f\u6bd4\u8f83\u903b\u8f91<\/li>\n<li>[ ] \u663e\u793a\u6b63\u786e\/\u9519\u8bef\u53cd\u9988<\/li>\n<li>[ ] \u6d4b\u8bd5\u57fa\u672c\u529f\u80fd<\/li>\n<\/ul>\n<h3>\u7ec3\u4e602: \u8fdb\u9636\u529f\u80fd\uff0845\u5206\u949f\uff09<\/h3>\n<ul>\n<li>[ ] \u6dfb\u52a0\u731c\u6d4b\u6b21\u6570\u7edf\u8ba1<\/li>\n<li>[ ] \u5b9e\u73b0\u5386\u53f2\u8bb0\u5f55\u663e\u793a<\/li>\n<li>[ ] \u6dfb\u52a0\u6700\u4f73\u6210\u7ee9\u4fdd\u5b58<\/li>\n<li>[ ] \u5b9e\u73b0\u91cd\u65b0\u5f00\u59cb\u529f\u80fd<\/li>\n<li>[ ] \u6dfb\u52a0\u8f93\u5165\u52a8\u753b\u6548\u679c<\/li>\n<\/ul>\n<h3>\u7ec3\u4e603: UI \u4f18\u5316\uff0830\u5206\u949f\uff09<\/h3>\n<ul>\n<li>[ ] \u6dfb\u52a0\u6b22\u8fce\u754c\u9762<\/li>\n<li>[ ] \u5b9e\u73b0\u731c\u6d4b\u52a8\u753b<\/li>\n<li>[ ] \u4f18\u5316\u79fb\u52a8\u7aef\u5e03\u5c40<\/li>\n<li>[ ] \u6dfb\u52a0\u97f3\u6548\u63d0\u793a<\/li>\n<li>[ ] \u7f8e\u5316\u53cd\u9988\u6837\u5f0f<\/li>\n<\/ul>\n<h3>\u7ec3\u4e604: \u529f\u80fd\u6269\u5c55\uff0860\u5206\u949f\uff09<\/h3>\n<ul>\n<li>[ ] \u6dfb\u52a0\u96be\u5ea6\u9009\u62e9\uff08\u7b80\u5355\/\u56f0\u96be\uff09<\/li>\n<li>[ ] \u5b9e\u73b0\u8ba1\u65f6\u5668\u529f\u80fd<\/li>\n<li>[ ] \u6dfb\u52a0\u63d0\u793a\u529f\u80fd\uff08\u663e\u793a\u8303\u56f4\uff09<\/li>\n<li>[ ] \u5b9e\u73b0\u591a\u4eba\u6a21\u5f0f<\/li>\n<li>[ ] \u6dfb\u52a0\u6210\u5c31\u7cfb\u7edf<\/li>\n<\/ul>\n<hr>\n<h2>\ud83d\udca1 \u5e38\u89c1\u95ee\u9898 FAQ<\/h2>\n<h3>Q1: Math.random() \u771f\u7684\u968f\u673a\u5417\uff1f<\/h3>\n<p><strong>A<\/strong>: \u4e0d\u662f\u771f\u968f\u673a\uff0c\u662f\u4f2a\u968f\u673a\u3002\u4f46\u5bf9\u4e8e\u6e38\u620f\u6765\u8bf4\u8db3\u591f\u4e86\u3002<\/p>\n<pre><code class=\"language-javascript\">\/\/ \u751f\u6210 1-100 \u7684\u968f\u673a\u6574\u6570\nMath.floor(Math.random() * 100) + 1;\n<\/code><\/pre>\n<h3>Q2: \u5982\u4f55\u9632\u6b62\u7528\u6237\u8f93\u5165\u65e0\u6548\u6570\u5b57\uff1f<\/h3>\n<p><strong>A<\/strong>: \u4f7f\u7528 HTML5 \u9a8c\u8bc1 + JavaScript \u9a8c\u8bc1\u3002<\/p>\n<pre><code class=\"language-html\">&lt;input type=&quot;number&quot; min=&quot;1&quot; max=&quot;100&quot;&gt;\n<\/code><\/pre>\n<pre><code class=\"language-javascript\">if (num &lt; 1 || num &gt; 100) {\n    \/\/ \u663e\u793a\u9519\u8bef\n}\n<\/code><\/pre>\n<h3>Q3: \u5982\u4f55\u8ba9\u6e38\u620f\u66f4\u6709\u8da3\uff1f<\/h3>\n<p><strong>A<\/strong>: \u53ef\u4ee5\u6dfb\u52a0\uff1a<\/p>\n<ul>\n<li>\u5012\u8ba1\u65f6\u6a21\u5f0f<\/li>\n<li>\u6709\u9650\u6b21\u731c\u6d4b<\/li>\n<li>\u63d0\u793a\u529f\u80fd<\/li>\n<li>\u96be\u5ea6\u7ea7\u522b<\/li>\n<\/ul>\n<h3>Q4: \u6700\u4f73\u6210\u7ee9\u5982\u4f55\u6301\u4e45\u5316\uff1f<\/h3>\n<p><strong>A<\/strong>: \u4f7f\u7528 localStorage\u3002<\/p>\n<pre><code class=\"language-javascript\">\/\/ \u4fdd\u5b58\nlocalStorage.setItem('bestScore', score);\n\n\/\/ \u8bfb\u53d6\nconst score = localStorage.getItem('bestScore');\n<\/code><\/pre>\n<hr>\n<h2>\ud83d\udcda \u62d3\u5c55\u5b66\u4e60<\/h2>\n<h3>\u63a8\u8350\u9879\u76ee<\/h3>\n<ul>\n<li><strong>\u77f3\u5934\u526a\u5200\u5e03<\/strong>\uff1a\u7406\u89e3\u6982\u7387\u548c\u9009\u62e9<\/li>\n<li><strong>\u4e95\u5b57\u68cb<\/strong>\uff1a\u5b66\u4e60 AI \u548c\u6e38\u620f\u903b\u8f91<\/li>\n<li><strong>\u8bb0\u5fc6\u7ffb\u724c<\/strong>\uff1a\u638c\u63e1\u72b6\u6001\u7ba1\u7406<\/li>\n<\/ul>\n<h3>\u76f8\u5173\u4e3b\u9898<\/h3>\n<ul>\n<li>\u6570\u7ec4\u65b9\u6cd5\uff08push\u3001filter\u3001map\uff09<\/li>\n<li>\u5bf9\u8c61\u548c\u7c7b<\/li>\n<li>DOM \u64cd\u4f5c<\/li>\n<li>\u4e8b\u4ef6\u5904\u7406<\/li>\n<\/ul>\n<hr>\n<h2>\ud83c\udf93 \u603b\u7ed3<\/h2>\n<p><strong>\u4eca\u5929\u6211\u4eec\u5b66\u5230\u4e86<\/strong>\uff1a<\/p>\n<ul>\n<li>\u2705 Math.random() \u751f\u6210\u968f\u673a\u6570<\/li>\n<li>\u2705 \u8868\u5355\u9a8c\u8bc1\u548c\u7528\u6237\u8f93\u5165\u5904\u7406<\/li>\n<li>\u2705 \u6e38\u620f\u72b6\u6001\u7ba1\u7406<\/li>\n<li>\u2705 localStorage \u6570\u636e\u6301\u4e45\u5316<\/li>\n<li>\u2705 \u5b8c\u6574\u7684\u6e38\u620f\u5f00\u53d1\u6d41\u7a0b<\/li>\n<\/ul>\n<p><strong>\u5173\u952e\u6982\u5ff5<\/strong>\uff1a<\/p>\n<ul>\n<li>\ud83c\udfb2 <strong>\u968f\u673a\u6570<\/strong>\uff1aMath.random() + Math.floor()<\/li>\n<li>\ud83c\udfae <strong>\u6e38\u620f\u5faa\u73af<\/strong>\uff1a\u8f93\u5165 \u2192 \u5904\u7406 \u2192 \u53cd\u9988<\/li>\n<li>\ud83d\udcbe <strong>\u72b6\u6001\u7ba1\u7406<\/strong>\uff1a\u8ddf\u8e2a\u6e38\u620f\u6570\u636e<\/li>\n<li>\ud83c\udfa8 <strong>UI \u53cd\u9988<\/strong>\uff1a\u89c6\u89c9\u548c\u52a8\u753b\u6548\u679c<\/li>\n<\/ul>\n<hr>\n<p><strong>\u5b66\u4e60\u65f6\u95f4<\/strong>: 2026-03-17<br \/>\n<strong>\u96be\u5ea6<\/strong>: \u2b50\u2b50\u2b50\u2606\u2606<br \/>\n<strong>\u9884\u8ba1\u7528\u65f6<\/strong>: 3-4 \u5c0f\u65f6<br \/>\n<strong>\u5173\u952e\u8bcd<\/strong>: \u731c\u6570\u5b57\u3001\u968f\u673a\u6570\u3001\u6e38\u620f\u5f00\u53d1\u3001DOM\u64cd\u4f5c<br \/>\n<strong>\u76f8\u5173\u6807\u7b7e<\/strong>: #09-\u9879\u76ee\u5b9e\u6218<\/p>\n<hr>\n<p>\ud83d\udccc <strong>\u4e0b\u4e00\u6b65<\/strong>: \u5b66\u4e60 <a href=\".\/Day-22-%E9%A1%B9%E7%9B%AE4-%E6%89%93%E5%AD%97%E7%BB%83%E4%B9%A0%E6%B8%B8%E6%88%8F.md\">Day 22: \u9879\u76ee4-\u6253\u5b57\u7ec3\u4e60\u6e38\u620f<\/a>\uff0c\u7ee7\u7eed\u6e38\u620f\u5f00\u53d1\u4e4b\u65c5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Day 21: \u9879\u76ee3-\u731c\u6570\u5b57\u6e38\u620f \ud83c\udfaf Day 21 &#8211; \u731c\u6570\u5b57\u6e38\u620f \ud83d\udcc2 \u5206\u7c7b: 09-\u9879\u76ee\u5b9e\u6218  &#8230; <a title=\"Day-21-\u9879\u76ee3-\u731c\u6570\u5b57\u6e38\u620f\" class=\"read-more\" href=\"https:\/\/www.resilence.cn\/?p=286\" aria-label=\"\u7ee7\u7eed\u9605\u8bfbDay-21-\u9879\u76ee3-\u731c\u6570\u5b57\u6e38\u620f\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-286","post","type-post","status-publish","format-standard","hentry","category-studycoding"],"_links":{"self":[{"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/posts\/286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=286"}],"version-history":[{"count":1,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/posts\/286\/revisions"}],"predecessor-version":[{"id":287,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/posts\/286\/revisions\/287"}],"wp:attachment":[{"href":"https:\/\/www.resilence.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}