Bernabe, Justin B.
BSIT 1-B
JavaScript Exercise
Create a variable called firstName and assign a value Oey to it.
Answer.:
Let firstName = “Oey”;
Create a variable called x, assign the value 100 to it.
Answer.
Let x = 100;
Display the sum of 5+10, using two variables; x and y.
Answer.
Let x = 5;
Let y = 10;
Let sum = x + y;
Document.getElementById(“demo”).innerHTML = sum;
Create a variable called z, assign x+y to it, and display the result in an alert
box
Answer.
Let x = 5;
Let y = 10;
Let z = x + y;
Alert(z);
On one single name declare three variables in the following names and
values
Answer.
Let firstName = “John”, lastName = “Doe”, age = 15;
In the following sum, which is the operator?
Answer: +
What would the value of the variable ‘answer’ be, after this code is run?
Answer: 3
What would the value of the variable ‘fullName’ be, after this code is run?
Answer: Stefan Jones
What would the value of the variable ‘x’ be, after this code is run?
Answer: Jane25
What would the value of the variable ‘age’ be, after you press the A button
two times?
Answer: 18
What would the value of the variable ‘age’ be, after you press the A button
once?
Answer: 11
What would be shown when this code is run?
Answer: No
What would be shown when this code is run?
Answer: Yes
What would be shown when this code is run?
Answer: Yes
What would be shown when this code is run?
Answer: Yes
1.What will be the output of the following JavaScript code?
Answer: 123123
2.Guess the ternary operator used in the following example?
Answer: Conditional Operator
3.Initialization of variable can be done by writing operator in between
variable name and operand value.
Answer: =
4.What will be the output of the following script?
<script>
Var x = 5;
Document.write(x === “5”);
</script>
Answer: False
5.What will be the output of the following JavaScript code?
Function height()
Var height = 123.56;
Var type = (height>=190)? “tall”: “short”;
Return type;
Answer: Short
8. What type of value gets printed if we add following two variables.
Var a = “1”;
Var b = 5;
Answer: Text