Friday, June 9, 2017

Lab 17: JS Conditional Statement



  This lab was difficult to create as I found many difficulties to find how to function this lab. As we were supposed to create JS conditional statements; conditional statements are tags if, else, else if, or switch. As I created a button which had x=x+y, this button will add the two values. Then a pop up will appear asking if you if want to add these two values together. If you press confirm they will add these values if you press cancel. An error will occur, if you chose to add these values the value of the two inputs  will be replace with the x value. This will then perform a loop if you keep on adding these values.
 
<script>
function AdditionBy() {
var x = document.getElementById("a").value;
var y = document.getElementById("b").value;
var r = confirm("Would you like to replace the X value with the following answer?");

if (r == true) {
txt = document.getElementById("demo").innerHTML = Number(x) + Number(y);
document.getElementById("a").value = txt;
} else {
txt = document.getElementById("demo").innerHTML = Number(x) + Number(y);
}
document.getElementById("demo").innerHTML = txt;
}
</script>

This is JavaScript Code That I Used

No comments:

Post a Comment