1.
Inside which HTML element do we put the JavaScript?
Correct Answer
B. 2
Explanation
In HTML, JavaScript code is typically placed inside the `` element. This element is used to define client-side scripts, allowing JavaScript to be embedded directly within an HTML document. By placing JavaScript code within the `` tags, it can be executed and interact with the HTML elements on the page. Therefore, the correct answer is 2.
2.
Which of the following JavaScript statements use arrays?
Correct Answer
A. SetTimeout("a["+i+"]",1000)
Explanation
The correct answer is setTimeout("a["+i+"]",1000) because it uses an array (a) and accesses a specific element of the array (a[i]) within the setTimeout function.
3.
Which property would you use to redirect visitor to another page?
Correct Answer
A. Window.location.href
Explanation
The correct answer is window.location.href. This property is used to redirect a visitor to another page. It is a part of the window object in JavaScript and allows the manipulation of the current URL. By assigning a new URL to this property, the browser automatically navigates to the specified page. The other options mentioned, such as document.href, java.redirect.url, and link.redirect.href, are not valid properties or methods for redirecting visitors to another page.
4.
Wich best describe void?
Correct Answer
C. An operator
Explanation
Void is not a method, function, or statement. In programming, void is a data type that represents the absence of a value. It is often used to indicate that a method or function does not return any value. However, void is not an operator either, as operators are symbols or keywords used to perform specific operations on data. Hence, the correct answer is that void is not an operator.
5.
What is the correct JavaScript syntax to write "Hello World"?
Correct Answer
B. Document.write("Hello World")
Explanation
The correct JavaScript syntax to write "Hello World" is document.write("Hello World"). This method is used to display text or HTML content on a web page. It allows the developer to dynamically generate content and insert it into the document.
6.
How do you call a function named "myFunction"?
Correct Answer
B. MyFunction()
Explanation
To call a function named "myFunction", you need to use the syntax "myFunction()". This will execute the code inside the function and perform the desired actions or computations.
7.
How do you write a conditional statement for executing some statements only if "i" is equal to 5?
Correct Answer
C. If (i==5)
Explanation
The correct answer is "if (i==5)". This is the correct syntax for writing a conditional statement in many programming languages, including C++, Java, and Python. The "if" keyword is used to start the conditional statement, followed by the condition in parentheses. In this case, the condition is "i==5" which checks if the value of "i" is equal to 5. If the condition is true, then the statements inside the curly braces following the "if" statement will be executed.
8.
How many different kind of loops are there in JavaScript?
Correct Answer
A. Two. The "for" loop and the "while" loop
Explanation
The correct answer is two because JavaScript has two different types of loops: the "for" loop and the "while" loop. These loops allow for repetitive execution of a block of code until a certain condition is met. The "for" loop is typically used when the number of iterations is known, while the "while" loop is used when the number of iterations is uncertain and depends on a condition.
9.
How do you write a conditional statement for executing some statements only if "i" is NOT equal to 5?
Correct Answer
B. If (i != 5)
Explanation
The correct answer is "if (i != 5)". This conditional statement checks if the variable "i" is not equal to 5. If the condition is true, the specified statements within the if block will be executed.
10.
How does a "for" loop start?
Correct Answer
B. For (i = 0; i
Explanation
The correct answer is "for (i = 0; i < 5; i++)". This is the standard syntax for a "for" loop in most programming languages. It consists of three parts: the initialization (i = 0), the condition (i < 5), and the increment (i++). The loop will start by initializing the variable i to 0, then it will check if the condition i < 5 is true. If it is, the loop will execute the code inside the loop body. After each iteration, the increment will be executed (i++), updating the value of i. The loop will continue as long as the condition is true and will stop when the condition becomes false.
11.
What is the correct way to write a JavaScript array?
Correct Answer
A. Var txt = new Array("tim","shaq","kobe")
Explanation
The correct way to write a JavaScript array is by using the syntax var txt = new Array("tim","shaq","kobe"). This syntax creates a new array object called "txt" with three elements: "tim", "shaq", and "kobe".
12.
Onclick is equivalent to which two events in sequence
Correct Answer
C. Onmousedown and onmouseup
Explanation
The onclick event is triggered when a user clicks on an element. This event is equivalent to the onmousedown event, which occurs when the mouse button is pressed down, and the onmouseup event, which occurs when the mouse button is released. Therefore, the correct answer is "onmousedown and onmouseup".
13.
You define an array using
Correct Answer
A. Var myarray = new Array();
Explanation
The correct answer is "var myarray = new Array();". This is the correct way to define an array in JavaScript. The "new Array()" syntax is used to create a new instance of an array object, and assigning it to the variable "myarray" allows you to access and manipulate the array using that variable. The other options provided in the question are incorrect syntax and would result in a syntax error.
14.
How do you round the number 8.25, to the nearest whole number?
Correct Answer
B. Math.round(8.25)
Explanation
The correct answer is Math.round(8.25). The Math.round() function is used to round a number to the nearest whole number. In this case, 8.25 is rounded to 8.
15.
CHow do you find the largest number of 6 and 8?
Correct Answer
A. Math.max(6,8)
Explanation
The correct answer is Math.max(6,8). This is because the Math.max() function is used to find the largest number among the given inputs. In this case, the function is comparing the numbers 6 and 8 and returning the larger number, which is 8.
16.
How do you find the client's browser name?
Correct Answer
A. Navigator.appName
Explanation
The correct answer is navigator.appName. The navigator.appName property is used to find the name of the client's browser. It returns the name of the browser as a string. This property is commonly used in JavaScript to detect the browser type and perform browser-specific actions or optimizations.
17.
What is the correct JavaScript syntax for opening a new window called "window5" ?
Correct Answer
B. Window.open("http://www.ex-designz.net","window5")
Explanation
The correct JavaScript syntax for opening a new window called "window5" is window.open("http://www.ex-designz.net","window5"). This syntax uses the window.open() method to open a new window with the specified URL and window name.
18.
How do you put a message in the browser's status bar?
Correct Answer
A. Window.status = "put your message here"
Explanation
The correct answer is "window.status = 'put your message here'". This is because the "window.status" property allows you to set the text that appears in the browser's status bar. By assigning a message to this property, you can display your desired message in the status bar. The other options provided ("statusbar = 'put your message here'", "status('put your message here')", "window.status('put your message here')") are incorrect and will not achieve the desired result.
19.
EJERCICIO:
Definir una función que muestre información sobre una cadena de texto
que se le pasa como argumento. A partir de la cadena que se le pasa, la
función determina si esa cadena está formada sólo por mayúsculas, sólo
por minúsculas o por una mezcla de ambas.
20.
El factorial de un número entero n es una operación matemática que consiste en multiplicar todos los factores n x (n-1) x (n-2) x ... x 1. Así, el factorial de 5 (escrito como 5!) es igual a: 5! = 5 x 4 x 3 x 2 x 1 = 120
Utilizando la estructura for, crear un script que calcule el factorial de un número entero.