We need a script that will generate random code from scored ones, for example 2 codes: <script> </ script> and <html> </ html> we need the script to sometimes throw out <script> </ script> and sometimes <html> < / html>, everything should be in HTML + Javascript, PHP can not
- 3I am amazed more and more by interesting tasks. - Artem
- 2@Shrek task once spit, but how it is described, it is yes) Google just will not answer) - Palmervan
|
2 answers
var code = new Array("//code 1","//code 2","//code 3"); var rand = Math.floor(Math.random() * code.length); document.write(code[rand]); |
if((Math.random()).toFixed(0) == 0) document.write("script"); else document.write("html"); on javascript
- if you don’t pay attention to what you want to display) I just don’t see the connection between <html> </ html> and <script> </ script> - namak
- I mean a script in which 2 codes are crammed, and he should accidentally output them, well, or at least in turn - Semyon
- Well, instead of "document.write (" script ");" write your any code in javascript, I wrote - (Math.random ()). toFixed (0) is randomly the number 0 or 1. if this is the case number 0, then execute document.write ("script"), otherwise execute document .write ("html") you take your code and insert instead of document.write ("script") ... or write more specifically what you need. - namak
- there is a suspicion that the author wants continuous execution of some pieces of code on the page or not ??? - namak
|