-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBabel.js
More file actions
68 lines (65 loc) · 1.55 KB
/
Copy pathBabel.js
File metadata and controls
68 lines (65 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function babel()
{
var output=document.getElementById("output");
var term=document.getElementById("term").value;
var row=document.getElementById("row").value;
var direction=document.getElementById("direction").value;
output.innerHTML="";
if(direction=="")
{
for (counter=0;counter<row;counter++)
{
output.innerHTML+=term+"<br>";
}
}
else if(direction=="horizontal")
{
for (counter=0;counter<row;counter++)
{
output.innerHTML+=term+"<br>";
output.innerHTML+="<br>";
}
}
else if(direction=="vertical")
{
var str=setCharAt(term,Math.floor((Math.random() * term.length-1) + 1),' ');
for (counter=0;counter<row;counter++)
{
output.innerHTML+=str+"<br>";
}
}
else if(direction=="diagonal")
{
var blank=term.length-1;
for(counter=0;counter<row;counter++)
{
term=document.getElementById("term").value;
term=setCharAt(term,blank,' ');
output.innerHTML+=term+"<br>";
blank-=2;
if (blank<0){
blank=term.length-1;
}
}
}
else if(direction=="ex1")
{
for (counter=0;counter<row;counter++)
{
term=setCharAt(term,Math.floor((Math.random() * term.length-1) + 1),' ');
output.innerHTML+=term+"<br>";
}
}
else if(direction=="ex2")
{
for (counter=0;counter<row;counter++)
{
var str=setCharAt(term,Math.floor((Math.random() * term.length-1) + 1),' ');
output.innerHTML+=str+"<br>";
}
}
}
function setCharAt(str,index,chr) {
if(index > str.length-1) return str;
return str.substr(0,index) + chr + str.substr(index+1);
}