-
Notifications
You must be signed in to change notification settings - Fork 0
/
animal array.js
65 lines (48 loc) · 2.43 KB
/
animal array.js
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
document.addEventListener('DOMContentLoaded', function() {
var part_1 = document.createElement('div');
var part_2 = document.createElement('select');
var part_3 = document.createElement('p');
part_3.style = "position:relative; left:400px; top:50px";
part_1.appendChild(part_2);
part_1.id="part_1";
part_2.id="part_2";
part_3.id="part_3";
part_3.innerText="Descriptions of Animals You Select Will appear here!!";
description_array=["Has a very Long Neck!!","The Best animal out there ;)","Has a lot stripes!","Has a very Long snout,also very big!!","Steals your acorns!", "Crows a lot!!","likes fish,also complains a lot","looks in headlights a lot!","Evil Henchmen in Lion King","Likes Honey!"]
name_array=['Giraffe','Greyhound','Zebra','Elephant','Squirrel','Bird','Cat','Deer','Hyena','Bear']
let newOption = new Option(name_array[0],value = description_array[0]);
part_2.add(newOption,undefined)
let newOption2 = new Option(name_array[1],value = description_array[1]);
part_2.add(newOption2,undefined)
let newOption3 = new Option(name_array[2],value = description_array[2]);
part_2.add(newOption3,undefined)
let newOption4 = new Option(name_array[3],value = description_array[3]);
part_2.add(newOption4,undefined)
let newOption5 = new Option(name_array[4],value = description_array[4]);
part_2.add(newOption5,undefined)
let newOption6 = new Option(name_array[5],value = description_array[5]);
part_2.add(newOption6,undefined)
let newOption7 = new Option(name_array[6],value=description_array[6]);
part_2.add(newOption7,undefined)
let newOption8 = new Option(name_array[7],value=description_array[7]);
part_2.add(newOption8,undefined)
let newOption9 = new Option(name_array[8],value=description_array[8]);
part_2.add(newOption9,undefined)
let newOption10 = new Option(name_array[9],value=description_array[9]);
part_2.add(newOption10,undefined)
document.body.appendChild(part_1);
document.body.appendChild(part_3);
}, false);
document.addEventListener("change", function() {
let x = document.getElementById("part_2").selectedIndex
y= document.getElementById("part_2")[x].value
document.getElementById("part_3").innerText = y;
});
//function state_change() {
// var x = document.getElementById("part_2").value;
// var y= document.createElement('div');
// y.innerHTML="works";
// document.body.appendChild(y);
// document.getElementById("part_3").innerHTML = "You selected: " + x;
//alert("I heard you!!")
//}