Lesson 3 この[N]はいくらですか?
あなたの 持ち物と 値段を 説明しよう。
Let’s write down your belongings. 寫下⾃⼰帶來的物品吧。
私の[N]は [場所/人] のです。
我的教科書是⽇本的。
My textbook is made from Japan.
この[N]は [数字] 円です。
它是1000⽇圓。
This [N] is 1000 yen
1. 名詞の選択
2. 場所または人の選択
3. 値段の入力
作成された文章一覧
${newPlace}
`; newOption.onclick = () => selectPlace(newOption, newPlace); placeOptions.appendChild(newOption); document.getElementById('newPlace').value = ''; } } // ランダム文章生成 function generateRandomSentence() { // 1. 名詞をランダム選択 const nounOptions = document.querySelectorAll('#nounOptions .option-item'); if (nounOptions.length === 0) return; const randomNounIndex = Math.floor(Math.random() * nounOptions.length); const randomNounElement = nounOptions[randomNounIndex]; const randomNounValue = randomNounElement.getAttribute('data-value'); selectNoun(randomNounElement, randomNounValue); // 2. 場所・人をランダム選択 const placeOptions = document.querySelectorAll('#placeOptions .option-item'); if (placeOptions.length === 0) return; const randomPlaceIndex = Math.floor(Math.random() * placeOptions.length); const randomPlaceElement = placeOptions[randomPlaceIndex]; const randomPlaceValue = randomPlaceElement.getAttribute('data-value'); selectPlace(randomPlaceElement, randomPlaceValue); // 3. ランダムな3桁の数値を生成 const randomPrice = Math.floor(Math.random() * 900) + 100; // 100-999の範囲 document.getElementById('price').value = randomPrice; // 4. createSentences関数を呼び出し createSentences(); } // 文章作成(自動的にリストに追加) function createSentences() { const price = document.getElementById('price').value; if (!selectedNoun) { alert('名詞を選択してください。'); return; } if (!selectedPlace) { alert('場所または人を選択してください。'); return; } if (!price) { alert('値段を入力してください。'); return; } const sentence1 = `この${selectedNoun}は${selectedPlace}のです。`; const sentence2 = `この${selectedNoun}は${price}円です。`; addToSentenceList(sentence1, sentence2); } // 文章をリストに追加 function addToSentenceList(sentence1, sentence2) { const sentenceList = document.getElementById('sentenceList'); const listItem = document.createElement('li'); listItem.className = 'sentence-item'; listItem.innerHTML = `${sentence1}
${sentence2}
`; sentenceList.appendChild(listItem); } // 全削除 function clearSentences() { document.getElementById('sentenceList').innerHTML = ''; } // イベントリスナーの設定 document.addEventListener('DOMContentLoaded', function() { // 名詞選択のイベントリスナー document.querySelectorAll('#nounOptions .option-item').forEach(item => { item.onclick = () => selectNoun(item, item.getAttribute('data-value')); }); // 場所・人選択のイベントリスナー document.querySelectorAll('#placeOptions .option-item').forEach(item => { item.onclick = () => selectPlace(item, item.getAttribute('data-value')); }); // Enterキーで追加 document.getElementById('newNoun').addEventListener('keypress', function(e) { if (e.key === 'Enter') { addNoun(); } }); document.getElementById('newPlace').addEventListener('keypress', function(e) { if (e.key === 'Enter') { addPlace(); } }); document.getElementById('price').addEventListener('keypress', function(e) { if (e.key === 'Enter') { createSentences(); } }); });練習
作った文を 先生と一緒に 読んでみよう。