mardi 24 septembre 2019

I want to randomize letters in words, from my input

I would like to know how to change up words a bit from my textarea input. I wouldn't want all the words in the sentence to be scrambled, rather only (some) of the letters in (some) of the words. The word order has to be the same.

I was thinking of using var string_array = string.split(""); but I couldn't find a lot of documentation on this and I couldn't find any other options that would be good for me, either.

Does anybody have suggestions in how to do this?

<!--Made by MysteriousDuck#5764-->

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" type="text/css" href="style.css">
    <script src="textchanger.js"></script>
    <title>Text changer</title>
</head>

<body>

    <div class="container">

        <h1> Text Changer </h1>
        <h2> CAPS text changer</h2>

        <textarea type="text" autofocus="true" placeholder="input text" id="inputText" value="Input Value"
            spellcheck="false"></textarea>
        <button class="button button1" onclick="myConvertFunction()">Convert</button>
        <textarea type="text" placeholder="CoNvErTeD tExT" id="converted" value="Clear" readonly="true"
            spellcheck="false"></textarea>
        <button class="button button1" onclick="myCopyFunction(); eraseText();">Copy</button>

    </div>
</body>

</html>
/* Made by MysteriousDuck#5764 */

function myConvertFunction() {
    var x = document.getElementById("inputText").value;
    var foo = x.split("");
    var string = "";
    for (i = 0; i < foo.length; i++) {
        if (i % 2 == 0) {
            string += foo[i].toUpperCase();
        } else {
            string += foo[i];
        }
    }

    document.getElementById("converted").value = string;
}

function myCopyFunction() {
    var copyText = document.getElementById("converted");
    copyText.select();
    document.execCommand("copy");
    alert("Copied the text: " + copyText.value);
    eraseText();
}

function eraseText() {
    document.getElementById("converted").value = "";
    document.getElementById("inputText").value = "";
    document.getElementById("inputText").focus();
}

function randomizeLetters() {
    var x = document.getElementById("inputText").value;
}



Aucun commentaire:

Enregistrer un commentaire