In: Computer Science
For java script
1. Make a set of buttons that demonstrate strings. Feel free to combine these new buttons with the buttons of the previous HW if you like, but you don't have to.
2. Modify the button styles
3. Add a for loop, a while loop, and a do while loop. These should be activated by buttons to demonstrate the loops.
<!DOCTYPE html>
<html>
<body>
<h1>Set of Buttons</h1>
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "BMW", "Volvo", "Saab",
"Ford", "Fiat", "Audi";
}
</script>
<script>
var cars= {"BMW", "Volvo", "Saab", "Ford", "Fiat", "Audi"};
var text = "";
var i;
for (i = 0; i < cars.length; i++) {
text += cars[i] + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
<button onclick="myFunction1()">Click me</button>
<p id="demo1"></p>
<script>
function myFunction1() {
document.getElementById("demo1").innerHTML = "BMW", "Volvo",
"Saab", "Ford", "Fiat", "Audi";
}
</script>
<script>
var cars= {"BMW", "Volvo", "Saab", "Ford", "Fiat", "Audi"};
var text = "";
var i;
while (i < cars.length) {
text += cars[i] + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
<button onclick="myFunction2()">Click me</button>
<p id="demo2"></p>
<script>
function myFunction2() {
document.getElementById("demo2").innerHTML = "BMW", "Volvo",
"Saab", "Ford", "Fiat", "Audi";
}
</script>
<script>
var cars= {"BMW", "Volvo", "Saab", "Ford", "Fiat", "Audi"};
var text = "";
var i;
do {
text += cars[i] + "<br>";
}
while(i<cars.length)
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>