0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JSでおみくじ

Last updated at Posted at 2019-12-26

'use strict';

const btn = document.getElementById('btn');
const kiroku = document.getElementById('kiroku');

let count = 0;
let list;

const click = btn.addEventListener('click',function omikuji(){

count++;
const number = Math.random();

if(number < 0.3 ){
    btn.textContent='唐揚げ';
    btn.style.color = 'yellow';
    alert('ぴよ!');
}else if(number < 0.7){
    btn.textContent = 'チキン南蛮';
    btn.style.color = 'blue';
}else{
    btn.textContent = '西京焼き';
    btn.style.color = 'green'
}

if(count > 0){
    list = document.createElement('li');
           list.setAttribute('id',count);
           list.textContent =`${count}回目は${btn.textContent}`;
           kiroku.appendChild(list);
}
});

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?