I would like to randomly display the characters entered by the user.
For example, if you type "Fish", "Ni", and "Rice", I would like to create a script that randomly changes the order, such as "Ni-go-han-san-ka" and "Rice-Fish-Niku".
If there are only two entries, I would like to randomly display only those two.
If I were to create a variable for each input item, I think it would be better to display the variable at random, but I don't know how to automatically ignore the blank when there is a blank and display a variable that is not a blank.In the first place, I don't know how to display the contents of variables randomly.
javascript
Like a comment said you need to get the input into variables somehow
For simplicity we can use window.prompt
, then to select a random one we should store each variable in an area, then to display it where can just use document.body.innerHTML
So
<body>
<Script>
var things = [ ]
varone=prompt("enter one thing")
things.push(one)
one=prompt("enter one other thing")
things.push(one)
one=prompt("enter one more thing")
things.push(one)
/*
Now we loop through it randomly using Math.random and Math.floor
*/
var toytawl=""
for(var index=0;index<things.length;index++){
var found = Math.floor (Math.random() *things.length)
toytawl+=things [found]
things.splice(found,1)
}
</Script>
</Body>
Translation from Google translate
I was told that for some reason I had to get input into the variable like the comment
To make it easier, simply use window.prompt
and select random variables by storing each variable in a region and using document.body.innerHTML to display it.
That's right
<Body>
<Body>
var things = [ ]
varone=prompt ("Please enter one")
things.push(one)
one = prompt ("Please enter one more")
things.push (one)
one = prompt ("Please enter one more")
things.push (one)
/ *
Then loop randomly using Math.random and Math.floor.
* /
var toytawl=""
for (var index=0;index<things.length;index++) {
var found = Math.floor (Math.random() *things.length)
toytawl=things [found]
things.splice (found, 1)
}
document.body.innerHTML = toytawl
</Script>
</Body>
translation from Google Translation
366 Is there any other way to save the Python database?
374 I want an event to happen when I click on a particular image on tkinter.
355 Unity Virtual Stick Does Not Return to Center When You Release Your Finger
362 To Limit Column Values to Strings in a String List Using sqlalchemy
361 Add dataframe values of the same structure without column names
© 2023 OneMinuteCode. All rights reserved.