-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
34 lines (26 loc) · 957 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const RANDOM_SENTENCE_URL_API = "https://api.quotable.io/random"
const typeDisplay = document.getElementById("type-display");
// 非同期でランダムな文章を取得する
function GetRandomSentence()
{
return fetch(RANDOM_SENTENCE_URL_API)
.then((responce) => responce.json())
.then((data) => data.content);
}
// ランダムな文章を取得して表示する
async function RenderNextSentence()
{
const sentence = await GetRandomSentence();
console.log(sentence);
typeDisplay.innerText = sentence;
// 文章を一文字ずつ分解してspanタグを生成する。
let oneText = sentence.split("");
// console.log(oneText);
oneText.forEach((character) => {
const characterSpan = document.createElement("span");
characterSpan.innerText = character;
// console.log(characterSpan);
typeDisplay.appendChild(characterSpan);
});
}
RenderNextSentence();