-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
4,389 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
const automerkit = ["Toyota", "Honda", "Ford", "Chevrolet"]; | ||
|
||
|
||
const pyoramerkit = ["Finnair", "Japan Airlines", "Fly emirates"]; | ||
|
||
|
||
console.log("Automerkit:"); | ||
for (let i = 0; i < automerkit.length; i++) { | ||
console.log(automerkit[i]); | ||
} | ||
|
||
|
||
console.log("\nLentokonemerkit:"); | ||
for (let i = 0; i < pyoramerkit.length; i++) { | ||
console.log(pyoramerkit[i]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
const marjat = ["mansikka", "mustikka", "vadelma"]; | ||
|
||
|
||
marjat.push("herukka", "kirsikka", "metsämansikka"); | ||
|
||
|
||
console.log("Päivitetty marjat-taulukko:", marjat); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const marjat = ["mansikka", "mustikka", "vadelma"]; | ||
|
||
marjat.pop(); | ||
|
||
console.log("Päivitetty marjat-taulukko:", marjat); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const ikä = 17 | ||
|
||
if (ikä < 18){ | ||
console.log("Et ole täysiikäinen") | ||
} | ||
else { | ||
console.log("olet täysiikäinen") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const lampotilat = [18, 13, 21.3, 17, 14, 25.3, 17]; | ||
|
||
const paivat = ["Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai", "Sunnuntai"]; | ||
|
||
for (let i = 0; i < paivat.length; i++) { | ||
const keskiarvo = lampotilat[i]; | ||
console.log(`${paivat[i]} ${keskiarvo} astetta`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Blackjack</title> | ||
</head> | ||
<body> | ||
|
||
<h1>Blackjack</h1> | ||
<button onclick="aloitaPeli()">Aloita peli</button> | ||
<button onclick="otaLisaaKortti()">Ota lisää kortteja</button> | ||
<button onclick="pysaytaPeli()">Älä otakortteja</button> | ||
|
||
|
||
<div id="pelaajanKortit"></div> | ||
<div id="tietokoneenKortit"></div> | ||
<div id="pisteet"></div> | ||
<div id="voittaja"></div> | ||
|
||
<script> | ||
let pelaajanKortit = []; | ||
let tietokoneenKortit = []; | ||
let peliKaynnissa = false; | ||
|
||
function aloitaPeli() { | ||
pelaajanKortit = [arvoKortti(), arvoKortti()]; | ||
tietokoneenKortit = [arvoKortti(), arvoKortti()]; | ||
peliKaynnissa = true; | ||
|
||
paivitaKortit(); | ||
laskePisteet(); | ||
document.getElementById('voittaja').textContent = ''; // Tyhjennetään voittajatieto | ||
} | ||
|
||
function otaLisaaKortti() { | ||
if (peliKaynnissa) { | ||
pelaajanKortit.push(arvoKortti()); | ||
paivitaKortit(); | ||
laskePisteet(); | ||
|
||
// Tarkistetaan, onko pelaaja mennyt yli 21 pisteen | ||
if (laskeKorttienSumma(pelaajanKortit) > 21) { | ||
peliKaynnissa = false; | ||
tarkistaVoittaja(); | ||
} | ||
} | ||
} | ||
|
||
function pysaytaPeli() { | ||
if (peliKaynnissa) { | ||
// Tietokoneen vuoro ottaa kortteja automaattisesti | ||
while (laskeKorttienSumma(tietokoneenKortit) < 17) { | ||
tietokoneenKortit.push(arvoKortti()); | ||
} | ||
|
||
// Päivitetään näkymä | ||
paivitaKortit(); | ||
laskePisteet(); | ||
|
||
peliKaynnissa = false; | ||
tarkistaVoittaja(); | ||
} | ||
} | ||
|
||
|
||
|
||
function arvoKortti() { | ||
const kortit = ['Hertta', 'Risti', 'Ruutu', 'Pata']; | ||
const numerot = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jätkä', 'Kuningatar', 'Kuningas']; | ||
|
||
const satunnainenMaa = kortit[Math.floor(Math.random() * kortit.length)]; | ||
const satunnainenNumero = numerot[Math.floor(Math.random() * numerot.length)]; | ||
|
||
return satunnainenNumero + ' ' + satunnainenMaa; | ||
} | ||
|
||
function paivitaKortit() { | ||
const pelaajanKortitElementti = document.getElementById('pelaajanKortit'); | ||
const tietokoneenKortitElementti = document.getElementById('tietokoneenKortit'); | ||
|
||
pelaajanKortitElementti.textContent = 'Pelaajan kortit: ' + pelaajanKortit.join(', '); | ||
tietokoneenKortitElementti.textContent = 'Tietokoneen kortit: ' + tietokoneenKortit.join(', '); | ||
} | ||
|
||
function laskePisteet() { | ||
const pisteetElementti = document.getElementById('pisteet'); | ||
pisteetElementti.textContent = 'Pisteet: ' + laskeKorttienSumma(pelaajanKortit); | ||
} | ||
|
||
function laskeKorttienSumma(kortit) { | ||
let summa = 0; | ||
let ässät = 0; | ||
|
||
for (let kortti of kortit) { | ||
const arvo = kortti.split(' ')[0]; | ||
if (arvo === 'Jätkä' || arvo === 'Kuningatar' || arvo === 'Kunkku') { | ||
summa += 10; | ||
} else if (arvo === 'Ässä') { | ||
summa += 11; | ||
ässät++; | ||
} else { | ||
summa += parseInt(arvo); | ||
} | ||
} | ||
|
||
while (summa > 21 && ässät > 0) { | ||
summa -= 10; | ||
ässät--; | ||
} | ||
|
||
return summa; | ||
} | ||
|
||
function tarkistaVoittaja() { | ||
const pelaajanPisteet = laskeKorttienSumma(pelaajanKortit); | ||
const tietokoneenPisteet = laskeKorttienSumma(tietokoneenKortit); | ||
|
||
const voittajaElementti = document.getElementById('voittaja'); | ||
|
||
if (pelaajanPisteet > 21) { | ||
voittajaElementti.textContent = 'Tietokone voittaa! Pelaaja meni yli 21 pisteen.'; | ||
} else if (tietokoneenPisteet > 21) { | ||
voittajaElementti.textContent = 'Pelaaja voittaa! Tietokone meni yli 21 pisteen.'; | ||
} else if (pelaajanPisteet > tietokoneenPisteet) { | ||
voittajaElementti.textContent = 'Pelaaja voittaa! Pelaajan pistemäärä on lähempänä 21.'; | ||
} else if (pelaajanPisteet < tietokoneenPisteet) { | ||
voittajaElementti.textContent = 'Tietokone voittaa! Tietokoneen pistemäärä on lähempänä 21.'; | ||
} else { | ||
voittajaElementti.textContent = 'Tasapeli! Pistemäärät ovat samat.'; | ||
} | ||
} | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head>> | ||
<title>Lääkityksen seuranta</title> | ||
<style> | ||
button { | ||
margin: 5px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<h1>Lääkityksen Seuranta</h1> | ||
|
||
<label for="suositus">Suositusmäärä:</label> | ||
<input type="number" id="suositus" min="1" value="10"> | ||
<button onclick="asetaSuositus()">Aseta Suositus</button> | ||
|
||
<br> | ||
|
||
<button onclick="annaLääke(1)">Anna Lääke (1)</button> | ||
<button onclick="annaLääke(2)">Anna Lääke (2)</button> | ||
<button onclick="annaLääke(5)">Anna Lääke (5)</button> | ||
|
||
<br> | ||
|
||
<p><strong>Lääkkeen annostelun tila:</strong></p> | ||
<p>Kerrat annettu: <span id="kerrat">0</span></p> | ||
<p>Viimeisin annos: <span id="viimeisin">Ei annettu</span></p> | ||
<p>Suurin annos: <span id="suurin">Ei annettu</span></p> | ||
<p>Jäljellä oleva annos: <span id="jäljellä">-</span></p> | ||
<p><strong>Suurin annettu annos:</strong> <span id="suurinAnnos">Ei annettu</span></p> | ||
<p><strong>Ylitettiinkö suositusmäärä:</strong> <span id="ylitettiin">Ei</span></p> | ||
|
||
<script> | ||
let suositusmaara = 10; | ||
let kerrat = 0; | ||
let viimeisinAnnos = null; | ||
let suurinAnnos = null; | ||
|
||
function asetaSuositus() { | ||
suositusmaara = parseInt(document.getElementById('suositus').value); | ||
resetoiTiedot(); | ||
} | ||
|
||
function annaLääke(annos) { | ||
kerrat++; | ||
if (viimeisinAnnos !== null) { | ||
if (annos > suurinAnnos || suurinAnnos === null) { | ||
suurinAnnos = annos; | ||
} | ||
|
||
const suurempi = annos > viimeisinAnnos ? 'Suurempi' : 'Pienempi'; | ||
document.getElementById('viimeisin').innerText = `${annos} (${suurempi})`; | ||
} else { | ||
document.getElementById('viimeisin').innerText = annos; | ||
} | ||
|
||
viimeisinAnnos = annos; | ||
document.getElementById('kerrat').innerText = kerrat; | ||
document.getElementById('suurin').innerText = suurinAnnos; | ||
|
||
const jäljellä = suositusmaara - kerrat; | ||
document.getElementById('jäljellä').innerText = jäljellä < 0 ? 0 : jäljellä; | ||
|
||
document.getElementById('suurinAnnos').innerText = suurinAnnos; | ||
document.getElementById('ylitettiin').innerText = jäljellä < 0 ? 'Kyllä' : 'Ei'; | ||
} | ||
|
||
function resetoiTiedot() { | ||
kerrat = 0; | ||
viimeisinAnnos = null; | ||
suurinAnnos = null; | ||
|
||
document.getElementById('kerrat').innerText = 0; | ||
document.getElementById('viimeisin').innerText = 'Ei annettu'; | ||
document.getElementById('suurin').innerText = 'Ei annettu'; | ||
document.getElementById('jäljellä').innerText = '-'; | ||
document.getElementById('suurinAnnos').innerText = 'Ei annettu'; | ||
document.getElementById('ylitettiin').innerText = 'Ei'; | ||
} | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Noppapeli</title> | ||
<style> | ||
#result { | ||
font-size: 18px; | ||
margin-top: 20px; | ||
} | ||
|
||
#total { | ||
font-size: 16px; | ||
margin-top: 10px; | ||
} | ||
|
||
#maxSum { | ||
font-size: 16px; | ||
margin-top: 10px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<h1>Noppapeli</h1> | ||
|
||
<label for="rounds">Syötä kierrosten määrä:</label> | ||
<input type="number" id="rounds" min="1" value="1"> | ||
<button onclick="rollDice()">Heitä noppaa</button> | ||
|
||
<div id="result"></div> | ||
<p id="total"></p> | ||
<p id="maxSum"></p> | ||
|
||
<script> | ||
function rollDice() { | ||
var rounds = document.getElementById("rounds").value; | ||
var resultElement = document.getElementById("result"); | ||
var totalElement = document.getElementById("total"); | ||
var maxSumElement = document.getElementById("maxSum"); | ||
resultElement.innerHTML = ""; | ||
|
||
var totalSum = 0; | ||
var maxSum = 0; | ||
|
||
for (var i = 0; i < rounds; i++) { | ||
var dice1 = Math.floor(Math.random() * 6) + 1; | ||
var dice2 = Math.floor(Math.random() * 6) + 1; | ||
var total = dice1 + dice2; | ||
|
||
var roundResult = document.createElement("p"); | ||
roundResult.textContent = "Kierros " + (i + 1) + ": Noppa 1: " + dice1 + ", Noppa 2: " + dice2 + ", Yhteensä: " + total; | ||
resultElement.appendChild(roundResult); | ||
|
||
totalSum += total; | ||
|
||
if (total > maxSum) { | ||
maxSum = total; | ||
} | ||
} | ||
|
||
totalElement.textContent = "Kaikkien heittojen summa: " + totalSum; | ||
maxSumElement.textContent = "Suurin heittokäden summa: " + maxSum; | ||
} | ||
</script> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.