I created a function in js that lets me choose a random book from a list.
function randomIntFromInterval(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min)
}
const rndInt = randomIntFromInterval(1 , 27)
switch(rndInt){
case 1:
console.log('Beze mnie jesteś nikim. Przemoc w polskich domach');
break;
case 2:
console.log('Frankenstein')
break;
case 3:
console.log('The house on the Mango Street')
break;
case 4:
console.log('These Ghosts Are Family')
break;
case 5:
console.log('The Catcher in the Rye')
break;
case 6:
console.log('Norwegian Wood')
break;
case 7:
console.log('1984')
break;
case 8:
console.log('No Longer Human')
break;
case 9:
console.log('Winter in Sokcho')
break;
case 10:
console.log('Belonging')
break;
case 11:
console.log('Strange Bedfellows')
break;
case 12:
console.log('Circe')
break;
case 13:
console.log('Red, White & Royal Blue')
break;
case 14:
console.log('Kim Jiyoung, Born 1982')
break;
case 15:
console.log('Girl, WOmen, Other')
break;
case 16:
console.log('Aristotle 1')
break;
case 17:
console.log('They Both Die at the End')
break;
case 18:
console.log('Ucieczka od bezradnosci')
break;
case 19:
console.log('Grown Ups')
break;
case 20:
console.log('Men Explain Things to Me')
break;
case 21:
console.log('Klara and the Sun')
break;
case 22:
console.log('Komodo')
break;
case 23:
console.log('The Mind of a Murderer');
break;
case 24:
console.log('Czula przewodniczka')
break;
case 25:
console.log('Whats mine and yours')
break;
case 26:
console.log('The Japanese Devil')
break;
case 27:
console.log('The 7 Husbands of Evelynn Hugo')
break;
}
so it works and in the terminal I can see the titles of the books, but I can't quite put it as a function in HTML. I wanted to make a simple page where you can click a button and there will be a little field where the title would pop up. So far I created this
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="book gen/book generator.css">
</head>
<body>
<div class="introduction">
<h1>Rain's book randomizer 0.1v</h1>
<p>Just click the button down below and computer will choose a book for you</p>
<button onclick="console.log(rndInt)" type="button">Click me!</button>
</div>
<script>
function randomIntFromInterval(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min)
}
const rndInt = randomIntFromInterval(1 , 27)
switch(rndInt){
case 1:
console.log('Beze mnie jesteś nikim. Przemoc w polskich domach');
break;
case 2:
console.log('Frankenstein')
break;
case 3:
console.log('The house on the Mango Street')
break;
case 4:
console.log('These Ghosts Are Family')
break;
case 5:
console.log('The Catcher in the Rye')
break;
case 6:
console.log('Norwegian Wood')
break;
case 7:
console.log('1984')
break;
case 8:
console.log('No Longer Human')
break;
case 9:
console.log('Winter in Sokcho')
break;
case 10:
console.log('Belonging')
break;
case 11:
console.log('Strange Bedfellows')
break;
case 12:
console.log('Circe')
break;
case 13:
console.log('Red, White & Royal Blue')
break;
case 14:
console.log('Kim Jiyoung, Born 1982')
break;
case 15:
console.log('Girl, WOmen, Other')
break;
case 16:
console.log('Aristotle 1')
break;
case 17:
console.log('They Both Die at the End')
break;
case 18:
console.log('Ucieczka od bezradnosci')
break;
case 19:
console.log('Grown Ups')
break;
case 20:
console.log('Men Explain Things to Me')
break;
case 21:
console.log('Klara and the Sun')
break;
case 22:
console.log('Komodo')
break;
case 23:
console.log('The Mind of a Murderer');
break;
case 24:
console.log('Czula przewodniczka')
break;
case 25:
console.log('Whats mine and yours')
break;
case 26:
console.log('The Japanese Devil')
break;
case 27:
console.log('The 7 Husbands of Evelynn Hugo')
break;
}
</script>
</body>
</html>
any ideas ?