質問するログイン新規登録

回答編集履歴

3

不必要な行を削除

2018/03/18 15:34

投稿

defghi1977
defghi1977

スコア4756

answer CHANGED
@@ -10,7 +10,6 @@
10
10
  let result = ++i % 3 == 0 || i.toString().match(/3/) ? "aho!" : i;
11
11
  out.value += `${result}\n\r`;
12
12
  if(i >= max){
13
- document.close();
14
13
  clearInterval(h);
15
14
  }
16
15
  }, 1000);

2

FireFoxでも動作するように内容を変更, 一部をテンプレートリテラルに変更

2018/03/18 15:34

投稿

defghi1977
defghi1977

スコア4756

answer CHANGED
@@ -1,16 +1,21 @@
1
1
  例えばこんな
2
2
 
3
+ ```HTML
4
+ <output id="out" style="white-space:pre;"></output>
3
- ```JavaScript
5
+ <script>
6
+ "use strict";
4
7
  {
5
- const max = 100;
6
8
  let i = 0;
7
- const h = setInterval(() => {
9
+ const max = 100, h = setInterval(() => {
8
10
  let result = ++i % 3 == 0 || i.toString().match(/3/) ? "aho!" : i;
9
- document.write(result + "<br/>");
11
+ out.value += `${result}\n\r`;
10
12
  if(i >= max){
11
13
  document.close();
12
14
  clearInterval(h);
13
15
  }
14
16
  }, 1000);
15
17
  }
18
+ </script>
16
- ```
19
+ ```
20
+ NOTE:
21
+ 当初は`document.write`を使っていましたが, FireFoxにおいて`setInterval`による非同期処理と相性が悪かったため, 出力先を変更しています.

1

関数名を省略できるような構造に

2018/03/18 15:27

投稿

defghi1977
defghi1977

スコア4756

answer CHANGED
@@ -4,14 +4,13 @@
4
4
  {
5
5
  const max = 100;
6
6
  let i = 0;
7
- function count(){
7
+ const h = setInterval(() => {
8
8
  let result = ++i % 3 == 0 || i.toString().match(/3/) ? "aho!" : i;
9
9
  document.write(result + "<br/>");
10
10
  if(i >= max){
11
11
  document.close();
12
12
  clearInterval(h);
13
13
  }
14
- }
15
- const h = setInterval(count, 1000);
14
+ }, 1000);
16
15
  }
17
16
  ```