Add mix.html
This commit is contained in:
parent
38b7fc2ea8
commit
ce4ec36673
1 changed files with 35 additions and 0 deletions
35
mix.html
Normal file
35
mix.html
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fi">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Sanakirjainten sekoittaminen</title>
|
||||||
|
<script>
|
||||||
|
function shuffleWord(word) {
|
||||||
|
if (word.length <= 3) {
|
||||||
|
return word; // Jätetään pienet sanat ennalleen
|
||||||
|
}
|
||||||
|
let middle = word.slice(1, -1).split('');
|
||||||
|
for (let i = middle.length - 1; i > 0; i--) {
|
||||||
|
const j = Math.floor(Math.random() * (i + 1));
|
||||||
|
[middle[i], middle[j]] = [middle[j], middle[i]];
|
||||||
|
}
|
||||||
|
return word[0] + middle.join('') + word[word.length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function shuffleText() {
|
||||||
|
let inputText = document.getElementById("inputText").value;
|
||||||
|
let words = inputText.split(' ');
|
||||||
|
let shuffledWords = words.map(word => shuffleWord(word));
|
||||||
|
document.getElementById("outputText").innerText = shuffledWords.join(' ');
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Sanojen keskimmäisten kirjainten sekoittaminen</h1>
|
||||||
|
<textarea id="inputText" rows="4" cols="50" placeholder="Kirjoita teksti tähän..."></textarea><br><br>
|
||||||
|
<button onclick="shuffleText()">Sekoita teksti</button><br><br>
|
||||||
|
<p><strong>Sekoitetut sanat:</strong></p>
|
||||||
|
<p id="outputText"></p>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue