Add mix2.html
This commit is contained in:
parent
ce4ec36673
commit
dd8f9e294c
1 changed files with 33 additions and 0 deletions
33
mix2.html
Normal file
33
mix2.html
Normal file
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="fi">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Toisen kirjaimen vaihtaminen</title>
|
||||
<script>
|
||||
function swapSecondLetter(word) {
|
||||
if (word.length <= 2) {
|
||||
return word; // Jätetään pienet sanat ennalleen
|
||||
}
|
||||
let secondLetter = word[1];
|
||||
let randomIndex = Math.floor(Math.random() * (word.length - 2)) + 2; // Varmistetaan, että vaihto tapahtuu 3. kirjaimen jälkeen
|
||||
let newWord = word[0] + word[randomIndex] + word.slice(2, randomIndex) + secondLetter + word.slice(randomIndex + 1);
|
||||
return newWord;
|
||||
}
|
||||
|
||||
function swapText() {
|
||||
let inputText = document.getElementById("inputText").value;
|
||||
let words = inputText.split(' ');
|
||||
let swappedWords = words.map(word => swapSecondLetter(word));
|
||||
document.getElementById("outputText").innerText = swappedWords.join(' ');
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Toisen kirjaimen vaihtaminen satunnaisesti</h1>
|
||||
<textarea id="inputText" rows="4" cols="50" placeholder="Kirjoita teksti tähän..."></textarea><br><br>
|
||||
<button onclick="swapText()">Vaihda toisen kirjaimen paikkaa</button><br><br>
|
||||
<p><strong>Muunnetut sanat:</strong></p>
|
||||
<p id="outputText"></p>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue