Introduction to Web Development Practice Exam
What does HTML stand for?
A) HyperText Markup Language
B) HighText Machine Language
C) HyperTool Markup Language
D) None of the above
Answer: A
Which HTML tag is used to define an internal style sheet?
A) <style>
B) <script>
C) <link>
D) <css>
Answer: A
Which of the following is the correct HTML for inserting a line break?
A) <lb>
B) <break>
C) <br>
D) <linebreak>
Answer: C
Which HTML attribute specifies the destination of a link?
A) href
B) link
C) destination
D) src
Answer: A
Which of the following is the correct syntax for referring to an external JavaScript file?
A) <script src=”filename.js”>
B) <script href=”filename.js”>
C) <script file=”filename.js”>
D) <script link=”filename.js”>
Answer: A
Which CSS property is used to change the font of an element?
A) font-style
B) font-family
C) text-font
D) font-size
Answer: B
How do you select an element with the id “demo” in CSS?
A) #demo
B) .demo
C) demo
D) demo
Answer: A
Which HTML tag is used to display a picture on a web page?
A) <image>
B) <pic>
C) <img>
D) <picture>
Answer: C
In JavaScript, what is the correct syntax to display “Hello World” in the console?
A) echo(“Hello World”);
B) console.log(“Hello World”);
C) print(“Hello World”);
D) log(“Hello World”);
Answer: B
Which of the following is used to create a hyperlink in HTML?
A) <a>
B) <link>
C) <href>
D) <anchor>
Answer: A
What is the correct way to comment out a line in JavaScript?
A) // This is a comment
B) /* This is a comment */
C) <!– This is a comment –>
D) # This is a comment
Answer: A
Which property is used to change the background color in CSS?
A) color
B) bgcolor
C) background-color
D) background
Answer: C
What is the purpose of the alt attribute in the <img> tag?
A) To specify the image’s background color
B) To provide alternative text for the image
C) To link the image to a URL
D) To specify the image file type
Answer: B
Which HTML element is used to create a table?
A) <table>
B) <tab>
C) <tr>
D) <t>
Answer: A
Which of the following is the correct way to link an external CSS file to an HTML document?
A) <css href=”style.css”>
B) <link rel=”stylesheet” href=”style.css”>
C) <style link=”style.css”>
D) <stylesheet href=”style.css”>
Answer: B
Which method is used to add a class to an element in JavaScript?
A) element.addClass()
B) element.className()
C) element.addClassName()
D) element.classList.add()
Answer: D
What does CSS stand for?
A) Cascading Style Sheets
B) Creative Style Sheets
C) Computer Style Sheets
D) Colorful Style Sheets
Answer: A
Which property in CSS is used to change the text color?
A) text-color
B) color
C) font-color
D) text-style
Answer: B
Which event occurs when the user clicks on an HTML element in JavaScript?
A) onfocus
B) onchange
C) onclick
D) onmouseover
Answer: C
What does the DOMContentLoaded event in JavaScript do?
A) Triggers when the page fully loads, including images
B) Triggers when the DOM is ready for manipulation
C) Fires after the page’s CSS is applied
D) Runs when the user interacts with the page
Answer: B
What is the default value of the position property in CSS?
A) relative
B) static
C) absolute
D) fixed
Answer: B
Which CSS property is used to create space between the content and the border of an element?
A) margin
B) padding
C) border-spacing
D) spacing
Answer: B
Which of the following is used to select all <p> tags in a CSS file?
A) *p
B) p
C) .p
D) #p
Answer: B
What is the correct syntax for embedding JavaScript within an HTML document?
A) <script>…</script>
B) <javascript>…</javascript>
C) <js>…</js>
D) <jscript>…</jscript>
Answer: A
What is the use of the <div> tag in HTML?
A) To create a form
B) To group content together
C) To display images
D) To create tables
Answer: B
Which CSS property is used to control the text size?
A) font-size
B) text-size
C) font-style
D) text-style
Answer: A
What does the localStorage object do in JavaScript?
A) Stores data for the duration of the session
B) Stores data persistently in the browser
C) Stores data temporarily on the server
D) Stores cookies on the browser
Answer: B
Which of the following is the correct syntax for an if statement in JavaScript?
A) if (x == 5) {}
B) if x == 5 then {}
C) if x = 5 {}
D) if (x == 5) {}
Answer: D
Which of the following CSS properties is used to align text to the center?
A) text-align: center;
B) text-position: center;
C) align-text: center;
D) center-text: align;
Answer: A
Which of the following is a valid way to include a comment in JavaScript?
A) // This is a comment
B) /* This is a comment */
C) Both A and B
D) None of the above
Answer: C
Which of the following is used to set the background color of a webpage in CSS?
A) background-color
B) color
C) background
D) bg-color
Answer: A
Which tag is used to define a hyperlink in HTML?
A) <a>
B) <link>
C) <anchor>
D) <url>
Answer: A
How do you select an element with the class name “header” in CSS?
A) .header
B) #header
C) header
D) header
Answer: A
Which JavaScript method is used to remove an element from an array?
A) remove()
B) delete()
C) pop()
D) shift()
Answer: C
What does the float property do in CSS?
A) Positions an element at the top of the page
B) Positions an element to the left or right of its container
C) Makes the element stay in its original position
D) Adds transparency to an element
Answer: B
Which CSS property is used to add space between elements?
A) padding
B) margin
C) spacing
D) gap
Answer: B
How do you declare a variable in JavaScript?
A) var myVariable;
B) let myVariable;
C) const myVariable;
D) All of the above
Answer: D
Which of the following is the correct way to insert a comment in CSS?
A) // This is a comment
B) <!– This is a comment –>
C) /* This is a comment */
D) # This is a comment
Answer: C
Which HTML element is used to define a form?
A) <input>
B) <form>
C) <textarea>
D) <button>
Answer: B
Which JavaScript method is used to select an HTML element by its ID?
A) document.getElementById()
B) document.querySelector()
C) document.getElementsByClassName()
D) document.getElementByClass()
Answer: A
What is the purpose of the z-index property in CSS?
A) To control the position of an element
B) To specify the layering order of elements
C) To add shadow effects to elements
D) To add space between elements
Answer: B
Which HTML tag is used to define a table row?
A) <row>
B) <td>
C) <tr>
D) <th>
Answer: C
Which of the following is used to change the text alignment in CSS?
A) text-align: center;
B) align-text: center;
C) center-text: align;
D) text-center: align;
Answer: A
Which JavaScript function is used to display an alert box with a message?
A) alert()
B) console.log()
C) prompt()
D) message()
Answer: A
Which HTML tag is used to define a list item?
A) <item>
B) <li>
C) <list>
D) <ul>
Answer: B
What is the use of the <span> tag in HTML?
A) To create a section in the document
B) To group inline elements for styling purposes
C) To create a block element
D) To define a paragraph
Answer: B
Which CSS property is used to change the font size?
A) font-size
B) font-family
C) text-size
D) font-style
Answer: A
How can you make a numbered list in HTML?
A) <ol>
B) <ul>
C) <list>
D) <dl>
Answer: A
Which JavaScript method is used to change the content of an HTML element?
A) document.innerHTML()
B) document.setContent()
C) element.innerHTML()
D) element.setText()
Answer: C
Which of the following is the correct way to define a class selector in CSS?
A) .myClass
B) #myClass
C) myClass
D) *myClass*
Answer: A
Which of the following is used to add an external JavaScript file to an HTML document?
A) <script src=”file.js”>
B) <link src=”file.js”>
C) <javascript src=”file.js”>
D) <js src=”file.js”>
Answer: A
Which CSS property is used to change the color of the text?
A) color
B) text-color
C) font-color
D) text-style
Answer: A
What is the default value of the position property in CSS?
A) absolute
B) relative
C) fixed
D) static
Answer: D
How do you define an event handler in JavaScript for the click event?
A) element.onclick = function() {…};
B) element.addEventListener(“click”, function() {…});
C) Both A and B
D) element.onclickEvent() {…};
Answer: C
What is the purpose of the <!DOCTYPE html> declaration?
A) It defines the type of the document.
B) It specifies the version of HTML being used.
C) It defines the character encoding for the document.
D) It links to the external JavaScript file.
Answer: B
Which HTML element is used to define an unordered list?
A) <ul>
B) <ol>
C) <li>
D) <list>
Answer: A
What does the visibility property in CSS control?
A) Hides the element completely
B) Changes the color of the element
C) Makes the element visible or invisible but still takes up space
D) Adjusts the opacity of the element
Answer: C
Which JavaScript function is used to ask for input from the user?
A) prompt()
B) alert()
C) confirm()
D) message()
Answer: A
Which tag is used to define a table header in HTML?
A) <th>
B) <tr>
C) <td>
D) <thead>
Answer: A
Which JavaScript method is used to convert a string to uppercase?
A) string.toUpper()
B) string.toUpperCase()
C) string.toUpperCaseCase()
D) string.convertUpperCase()
Answer: B
Which of the following is the correct way to link an external CSS file to an HTML document?
A) <css src=”styles.css”>
B) <link href=”styles.css”>
C) <style src=”styles.css”>
D) <link rel=”stylesheet” href=”styles.css”>
Answer: D
Explanation: The <link> tag with rel=”stylesheet” is used to link an external CSS file. The href attribute points to the location of the CSS file.
Which of the following is the correct way to add a comment in JavaScript?
A) // This is a comment
B) <!– This is a comment –>
C) /* This is a comment */
D) Both A and C
Answer: D
Explanation: In JavaScript, single-line comments are written with //, while multi-line comments use /* comment */.
Which HTML tag is used to define a paragraph?
A) <p>
B) <para>
C) <section>
D) <div>
Answer: A
Explanation: The <p> tag is used to define a paragraph in HTML.
What does the box-sizing: border-box; property do in CSS?
A) Includes padding and border in the element’s total width and height
B) Adds a border to an element
C) Reduces the element’s width and height by the amount of padding
D) Sets the border width to 0
Answer: A
Explanation: The box-sizing: border-box; property includes the padding and border in the element’s total width and height, preventing the element from becoming larger than expected.
What does the visibility: hidden; property do in CSS?
A) Hides the element but still takes up space in the layout
B) Removes the element from the layout entirely
C) Changes the visibility of the background only
D) Hides the element and its contents completely
Answer: A
Explanation: The visibility: hidden; property hides the element but keeps its layout space intact. It differs from display: none;, which removes the element from the layout.
What is the purpose of the event.preventDefault() method in JavaScript?
A) To stop the browser from loading a page
B) To prevent the default behavior of an event
C) To trigger a new event
D) To log an event to the console
Answer: B
Explanation: The event.preventDefault() method prevents the default action associated with the event, such as preventing a form from submitting when clicking a submit button.
Which CSS property is used to set the space between words in a text?
A) letter-spacing
B) line-height
C) word-spacing
D) text-indent
Answer: C
Explanation: The word-spacing property controls the space between words in text.
What is the correct way to define a variable in JavaScript?
A) var x = 10;
B) let x = 10;
C) const x = 10;
D) All of the above
Answer: D
Explanation: In JavaScript, var, let, and const are used to define variables. let and const are more modern and recommended for block-scoped variables.
What is the default display property of an HTML <div> element?
A) block
B) inline
C) flex
D) none
Answer: A
Explanation: The default display value of a <div> element is block, which means it takes up the full width of its container.
Which of the following methods is used to create a new HTML element in JavaScript?
A) document.createElement()
B) document.addElement()
C) document.newElement()
D) document.create() Answer: A
Explanation: The document.createElement() method is used to create a new HTML element dynamically in JavaScript.
What is the purpose of the @media rule in CSS?
A) To apply styles for specific screen sizes or device types
B) To add media controls to a website
C) To import media files such as images
D) To link media files to a document
Answer: A
Explanation: The @media rule is used in CSS to apply different styles depending on the viewport size or device type, allowing for responsive design.
Which JavaScript method is used to add an element to the end of an array?
A) push()
B) add()
C) append()
D) pop()
Answer: A
Explanation: The push() method adds a new element to the end of an array.
Which of the following is a valid CSS selector for all <h1> elements?
A) h1{}
B) .h1{}
C) #h1{}
D) h1{};
Answer: A
Explanation: The h1{} selector targets all <h1> elements in the HTML document.
What does the this keyword refer to in JavaScript?
A) The global window object
B) The current function’s parameter
C) The object that the current function is a method of
D) The previous function
Answer: C
Explanation: The this keyword refers to the object that the current function is a method of, or the object that invoked the function.
Which of the following is the correct way to insert a JavaScript file into an HTML document?
A) <script href=”script.js”>
B) <js src=”script.js”>
C) <link src=”script.js”>
D) <script src=”script.js”></script>
Answer: D
Explanation: The <script> tag is used to link JavaScript files. The src attribute specifies the file path.
What does the opacity property do in CSS?
A) Controls the visibility of an element
B) Changes the color of an element
C) Sets the transparency level of an element
D) Hides an element completely
Answer: C
Explanation: The opacity property in CSS controls the transparency level of an element, where 1 is fully opaque and 0 is fully transparent.
What is the purpose of the href attribute in an HTML anchor tag?
A) Specifies the ID of a linked element
B) Defines the target frame for the link
C) Specifies the URL of the linked resource
D) Defines the action of the link
Answer: C
Explanation: The href attribute in an anchor (<a>) tag specifies the URL of the page the link points to.
Which CSS property is used to control the text color?
A) font-color
B) text-color
C) color
D) background-color
Answer: C
Explanation: The color property is used to set the text color in CSS.
Which of the following CSS values would you use to make an element invisible but still take up space?
A) opacity: 0;
B) visibility: hidden;
C) display: none;
D) visibility: visible;
Answer: B
Explanation: The visibility: hidden; property makes an element invisible but still occupies space in the layout.
What is the purpose of the console.log() method in JavaScript?
A) To display an alert box
B) To log information to the browser’s console
C) To pause the execution of code
D) To open the browser console
Answer: B
Explanation: The console.log() method is used to log information or debugging messages to the browser’s console.
Which of the following is used to specify the font size in CSS?
A) font-size: 14px;
B) size: 14px;
C) font: 14px;
D) font-size: small;
Answer: A
Explanation: The font-size property is used to specify the size of the font in CSS, typically using values like px, em, or rem.
Which HTML tag is used to display an image?
A) <image>
B) <img>
C) <src>
D) <picture>
Answer: B
Explanation: The <img> tag is used to display images in an HTML document.
Which of the following CSS properties is used to align text?
A) align-text
B) text-align
C) align
D) text-position
Answer: B
Explanation: The text-align property in CSS is used to set the horizontal alignment of text within an element.
Which JavaScript method is used to find the length of an array?
A) array.size()
B) array.length()
C) array.length
D) array.count()
Answer: C
Explanation: The length property returns the number of elements in an array.
Which CSS property is used to control the layout of a flex container?
A) display: flex;
B) layout: flex;
C) flex-container: true;
D) display: block;
Answer: A
Explanation: The display: flex; property enables a flexbox layout, allowing for flexible and responsive arrangements of elements.
What is the purpose of the onclick event in JavaScript?
A) To trigger when a mouse button is pressed
B) To trigger when an element is clicked
C) To trigger when a key is pressed
D) To trigger when a page is loaded
Answer: B
Explanation: The onclick event is triggered when an element is clicked, allowing you to run specific JavaScript code in response.
How can you make a website responsive?
A) By using fixed-width elements
B) By using @media queries
C) By removing padding and margin
D) By using large images
Answer: B
Explanation: Responsive web design is achieved by using @media queries to apply different styles based on the screen size or device type.
Which of the following tags is used to create a form in HTML?
A) <input>
B) <form>
C) <fieldset>
D) <select>
Answer: B
Explanation: The <form> tag is used to define a form in HTML.
What is the purpose of the charset attribute in the <meta> tag in HTML?
A) To specify the character encoding for the document
B) To define the page’s title
C) To specify the document’s background color
D) To add a stylesheet
Answer: A
Explanation: The charset attribute in the <meta> tag defines the character encoding used for the HTML document, typically set to UTF-8.
What does the border-radius property do in CSS?
A) Adds a shadow to the border
B) Rounds the corners of an element
C) Changes the border color
D) Makes the element’s border invisible
Answer: B
Explanation: The border-radius property is used to round the corners of an element, creating a circular or elliptical effect.
Which of the following is used to apply styles to elements with a specific class in CSS?
A) #class
B) .class
C) class=
D) *class
Answer: B
Explanation: The . (dot) is used to select elements with a specific class in CSS.
Which JavaScript method is used to remove the last element from an array?
A) pop()
B) shift()
C) remove()
D) delete()
Answer: A
Explanation: The pop() method removes the last element from an array and returns that element.
What is the purpose of the z-index property in CSS?
A) Controls the order of elements when they overlap
B) Defines the size of an element
C) Determines the visibility of an element
D) Changes the background color of an element
Answer: A
Explanation: The z-index property controls the stacking order of elements. Elements with a higher z-index appear in front of those with a lower value.
Which attribute is used to specify the URL in an HTML anchor tag?
A) url
B) src
C) href
D) target
Answer: C
Explanation: The href attribute specifies the URL that the link points to in an anchor (<a>) tag.
Which of the following is used to select an element with a specific ID in CSS?
A) .id
B) #id
C) *id
D) id:
Answer: B
Explanation: The # (hash) symbol is used to select elements with a specific ID in CSS.
What is the default value of the position property in CSS?
A) relative
B) absolute
C) fixed
D) static
Answer: D
Explanation: The default value of the position property is static, meaning elements are positioned according to the normal document flow.
Which JavaScript function is used to convert a string to an integer?
A) parseInt()
B) toInteger()
C) parseString()
D) convertInt()
Answer: A
Explanation: The parseInt() function is used to convert a string into an integer.
What does the float property do in CSS?
A) Aligns an element to the left or right, allowing text to flow around it
B) Centers an element on the page
C) Hides an element
D) Applies a transparency effect to an element
Answer: A
Explanation: The float property allows elements to be aligned to the left or right, letting text or other content flow around them.
Which of the following methods is used to remove the first element from an array in JavaScript?
A) pop()
B) shift()
C) unshift()
D) delete()
Answer: B
Explanation: The shift() method removes the first element from an array and shifts all other elements down by one.
Which HTML element is used to specify a table header?
A) <thead>
B) <th>
C) <header>
D) <h1>
Answer: B
Explanation: The <th> element is used to define a header cell in a table.
Which CSS property is used to set the width of an element?
A) height
B) width
C) size
D) display
Answer: B
Explanation: The width property in CSS is used to set the width of an element.
Which of the following JavaScript functions can be used to round a number to the nearest integer?
A) round()
B) Math.floor()
C) Math.round()
D) Math.ceil()
Answer: C
Explanation: The Math.round() function rounds a number to the nearest integer.
Which of the following is the correct syntax for declaring a JavaScript function?
A) function myFunction {}
B) function myFunction() {}
C) function = myFunction() {}
D) function() myFunction {}
Answer: B
Explanation: The correct syntax for declaring a function in JavaScript is function functionName() {}.
What is the correct way to write a JavaScript array?
A) var fruits = (1:”apple”, 2:”banana”, 3:”cherry”)
B) var fruits = [“apple”, “banana”, “cherry”]
C) var fruits = “apple”, “banana”, “cherry”
D) var fruits = {apple, banana, cherry}
Answer: B
Explanation: JavaScript arrays are written using square brackets, with values separated by commas, e.g., var fruits = [“apple”, “banana”, “cherry”];.
Which property is used to change the background color of an element in CSS?
A) background-color
B) color
C) bg-color
D) background
Answer: A
Explanation: The background-color property in CSS is used to set the background color of an element.
What does the getElementById() method do in JavaScript?
A) Selects an element by its class
B) Selects an element by its tag name
C) Selects an element by its ID
D) Selects an element by its index
Answer: C
Explanation: The getElementById() method selects an element with a specific ID in the DOM.
Which of the following CSS properties is used to control the font family?
A) font-type
B) font-family
C) font-style
D) text-font
Answer: B
Explanation: The font-family property is used to specify the font of an element.
What is the function of the clear property in CSS?
A) To prevent floating elements from overlapping with other elements
B) To clear all content from an element
C) To hide an element
D) To remove padding from an element
Answer: A
Explanation: The clear property is used to specify that an element should not be next to a floating element.
What does the Math.random() function do in JavaScript?
A) Returns a random number between 0 and 1
B) Generates a random boolean value
C) Returns a random integer between 1 and 100
D) Generates a random array
Answer: A
Explanation: The Math.random() function returns a random floating-point number between 0 (inclusive) and 1 (exclusive).
Which of the following HTML tags is used to define a line break?
A) <br>
B) <break>
C) <lb>
D) <hr>
Answer: A
Explanation: The <br> tag is used to insert a line break in HTML.
Which of the following CSS properties is used to align text within an element?
A) text-align
B) text-position
C) text-align-center
D) align-text
Answer: A
Explanation: The text-align property is used to align text horizontally within an element.
Which of the following is a correct HTML5 doctype declaration?
A) <!DOCTYPE html>
B) <!DOCTYPE HTML PUBLIC>
C) <!DOCTYPE html5>
D) <!DOCTYPE XHTML>
Answer: A
Explanation: The correct doctype declaration for HTML5 is <!DOCTYPE html>.
Which HTML element is used to create an unordered list?
A) <list>
B) <ul>
C) <ol>
D) <li>
Answer: B
Explanation: The <ul> element is used to create an unordered list in HTML, with list items specified by the <li> tag.
Which of the following JavaScript methods is used to add an event listener to an element?
A) addEvent()
B) addListener()
C) attachEvent()
D) addEventListener()
Answer: D
Explanation: The addEventListener() method is used to attach an event handler to an element.
Which of the following is a valid way to write a comment in CSS?
A) // This is a comment
B) /* This is a comment */
C) <!– This is a comment –>
D) # This is a comment
Answer: B
Explanation: CSS comments are written inside /* */ syntax.
What is the use of the DOMContentLoaded event in JavaScript?
A) Fires when all images have been loaded
B) Fires when the DOM is fully loaded and parsed
C) Fires when the window is resized
D) Fires when the document is printed
Answer: B
Explanation: The DOMContentLoaded event is fired when the HTML has been completely loaded and parsed, without waiting for stylesheets, images, and subframes.
Which JavaScript method is used to add a new element to the end of an array?
A) push()
B) unshift()
C) append()
D) pop()
Answer: A
Explanation: The push() method adds one or more elements to the end of an array.
Which HTML element is used to create a form input field for entering text?
A) <input type=”text”>
B) <input type=”password”>
C) <textarea>
D) <text>
Answer: A
Explanation: The <input type=”text”> element is used to create a text input field in a form.
What is the purpose of the meta tag in HTML?
A) Defines metadata such as page title
B) Provides links to external CSS files
C) Specifies JavaScript code
D) Adds images to the webpage
Answer: A
Explanation: The meta tag is used to provide metadata, like page description, author, and keywords.
Which of the following is used to declare a block of code as a function in JavaScript?
A) function functionName[] {}
B) function functionName() {}
C) func functionName() {}
D) declare functionName() {}
Answer: B
Explanation: The correct syntax for declaring a function in JavaScript is function functionName() {}.
Which of the following HTML elements is used to create a table row?
A) <td>
B) <tr>
C) <th>
D) <tr-row>
Answer: B
Explanation: The <tr> element is used to define a table row in HTML.
What does the align-items property do in CSS Flexbox?
A) Aligns items along the vertical axis
B) Aligns items along the horizontal axis
C) Aligns the content of a flex container
D) Aligns the entire container to the page
Answer: A
Explanation: The align-items property in Flexbox is used to align items along the vertical axis (cross-axis).
Which of the following CSS properties controls the space between elements in a flex container?
A) justify-content
B) align-content
C) gap
D) space-between
Answer: C
Explanation: The gap property defines the space between items in a Flexbox or Grid container.
What is the purpose of the localStorage object in JavaScript?
A) To store data for the current session only
B) To store data for an unlimited time
C) To store data on the server
D) To store large binary files
Answer: B
Explanation: The localStorage object allows you to store data persistently in the browser for an unlimited time (until the user clears it).
Which of the following HTML elements is used to define a list item in a numbered list?
A) <li>
B) <ul>
C) <ol>
D) <list>
Answer: A
Explanation: The <li> element is used to define a list item in both ordered (<ol>) and unordered (<ul>) lists.
Which method is used to find an element by its class name in JavaScript?
A) getElementByClass()
B) getElementsByClassName()
C) getClassName()
D) findByClass()
Answer: B
Explanation: The getElementsByClassName() method is used to get all elements with a specified class name.
What is the default value of the display property in CSS?
A) block
B) inline
C) none
D) inline-block
Answer: A
Explanation: By default, most HTML elements have a display value of block, meaning they take up the full width available and start on a new line.
What is the purpose of the src attribute in the <img> tag in HTML?
A) Specifies the size of the image
B) Defines the alt text for the image
C) Specifies the image source (URL)
D) Defines the border width for the image
Answer: C
Explanation: The src attribute in the <img> tag specifies the URL or file path to the image.
Which of the following JavaScript methods is used to remove an element from the DOM?
A) removeChild()
B) deleteElement()
C) remove()
D) detachElement()
Answer: C
Explanation: The remove() method is used to remove an element from the DOM.
What does the border-radius property do in CSS?
A) Sets the thickness of the border
B) Rounds the corners of an element
C) Specifies the color of the border
D) Controls the spacing between border and content
Answer: B
Explanation: The border-radius property in CSS is used to round the corners of an element.
Which of the following is the correct HTML element to include JavaScript in a webpage?
A) <script>
B) <js>
C) <javascript>
D) <jscript>
Answer: A
Explanation: The <script> element is used to include JavaScript code in an HTML document.
What is the purpose of the box-sizing property in CSS?
A) Defines the space between elements inside a box
B) Specifies how the total width and height of an element is calculated
C) Controls the layout of a flex container
D) Sets the alignment of the box inside the container
Answer: B
Explanation: The box-sizing property controls how the total width and height of an element are calculated, including padding and borders.
Which of the following JavaScript functions is used to find the length of a string?
A) stringLength()
B) length()
C) String.length()
D) length
Answer: D
Explanation: The length property is used to get the number of characters in a string.
Which of the following is used to define a form in HTML?
A) <form>
B) <input>
C) <button>
D) <fieldset>
Answer: A
Explanation: The <form> element is used to define an HTML form.
What is the correct way to refer to an external CSS file in an HTML document?
A) <link href=”style.css”>
B) <css src=”style.css”>
C) <style src=”style.css”>
D) <link rel=”stylesheet” type=”text/css” href=”style.css”>
Answer: D
Explanation: The correct way to link to an external CSS file is using the <link> element with rel=”stylesheet” and href attributes.
Which of the following JavaScript methods is used to parse a JSON string into a JavaScript object?
A) JSON.parse()
B) JSON.stringify()
C) parseJSON()
D) toJSON()
Answer: A
Explanation: The JSON.parse() method is used to convert a JSON string into a JavaScript object.
Which of the following CSS properties controls the spacing between the content of an element and its border?
A) padding
B) margin
C) border-spacing
D) spacing
Answer: A
Explanation: The padding property controls the space between the content of an element and its border.
Which JavaScript method is used to add a new element to the beginning of an array?
A) push()
B) shift()
C) unshift()
D) pop()
Answer: C
Explanation: The unshift() method adds one or more elements to the beginning of an array.
Which of the following is the correct syntax for a comment in JavaScript?
A) <!– This is a comment –>
B) /* This is a comment */
C) // This is a comment
D) // This is a comment //
Answer: C
Explanation: The correct syntax for a comment in JavaScript is // This is a comment.
Which of the following HTML attributes is used to specify the target of a link in the <a> tag?
A) target
B) href
C) link
D) url
Answer: A
Explanation: The target attribute is used to specify where the linked document will open (e.g., in the same window or a new tab).
Which of the following CSS properties is used to make text bold?
A) font-weight
B) text-weight
C) font-style
D) font-size
Answer: A
Explanation: The font-weight property is used to make text bold in CSS.
What does the setTimeout() method do in JavaScript?
A) Executes a function after a specified time delay
B) Sets the time for a webpage to refresh
C) Sets a timer to alert the user
D) Executes a function repeatedly at specified intervals
Answer: A
Explanation: The setTimeout() method is used to execute a function after a specified delay (in milliseconds).
Which of the following CSS properties is used to define the space between the elements in a grid container?
A) gap
B) grid-gap
C) grid-spacing
D) margin
Answer: A
Explanation: The gap property in CSS Grid is used to define the space between grid items.
Which of the following is a valid way to define a link in HTML?
A) <a href=”https://example.com”>Click here</a>
B) <link to=”https://example.com”>Click here</link>
C) <a href=”https://example.com” link>Click here</a>
D) <link src=”https://example.com”>Click here</link>
Answer: A
Explanation: The <a> element with the href attribute is used to define a hyperlink in HTML.
Which JavaScript method is used to display an alert box with a message?
A) alert()
B) console.log()
C) popup()
D) prompt()
Answer: A
Explanation: The alert() method is used to display an alert box with a specified message in JavaScript.
Which of the following HTML tags is used to define a hyperlink?
A) <a>
B) <link>
C) <href>
D) <button>
Answer: A
Explanation: The <a> tag is used to define a hyperlink in HTML.
What is the purpose of the z-index property in CSS?
A) Controls the font size
B) Controls the stacking order of elements
C) Sets the background color
D) Aligns elements to the center
Answer: B
Explanation: The z-index property controls the stacking order of elements, allowing you to specify which elements appear in front or behind others.
Which of the following is used to include a CSS file in an HTML document?
A) <link rel=”stylesheet” href=”style.css”>
B) <css href=”style.css”>
C) <style src=”style.css”>
D) <script href=”style.css”>
Answer: A
Explanation: The correct syntax to include an external CSS file is using the <link> tag with the rel=”stylesheet” attribute.
Which of the following JavaScript methods is used to add an element to the end of an array?
A) pop()
B) push()
C) shift()
D) unshift()
Answer: B
Explanation: The push() method adds one or more elements to the end of an array.
What is the purpose of the @media rule in CSS?
A) To define the style for specific media types or screen sizes
B) To set the default style for all media types
C) To link media files with CSS
D) To specify audio or video content for a webpage
Answer: A
Explanation: The @media rule is used in CSS to define styles for specific media types or screen sizes, enabling responsive web design.
Which of the following is used to create a checkbox in HTML?
A) <input type=”checkbox”>
B) <checkbox>
C) <form>
D) <input type=”radio”>
Answer: A
Explanation: The <input type=”checkbox”> element is used to create checkboxes in HTML forms.
Which of the following JavaScript methods is used to remove the first element from an array?
A) shift()
B) pop()
C) unshift()
D) delete()
Answer: A
Explanation: The shift() method removes the first element from an array.
Which CSS property is used to control the text color of an element?
A) color
B) font-color
C) text-color
D) background-color
Answer: A
Explanation: The color property in CSS is used to control the text color of an element.
Which of the following JavaScript events is triggered when a user clicks on an element?
A) onload
B) onclick
C) onmouseover
D) onchange
Answer: B
Explanation: The onclick event is triggered when a user clicks on an element.
Which CSS property controls the font size of text?
A) font-size
B) text-size
C) font-style
D) text-font
Answer: A
Explanation: The font-size property in CSS is used to control the size of the text.
Which HTML element is used to group inline elements in HTML?
A) <div>
B) <span>
C) <section>
D) <article>
Answer: B
Explanation: The <span> element is used to group inline elements together.
Which of the following HTML elements is used to define a footer for a document or section?
A) <footer>
B) <section>
C) <header>
D) <aside>
Answer: A
Explanation: The <footer> element is used to define the footer of a document or section.
What does the display: none property do in CSS?
A) Hides the element without affecting the layout
B) Removes the element from the page entirely
C) Makes the element visible again
D) Makes the element invisible but still takes up space in the layout
Answer: B
Explanation: The display: none property removes the element from the page entirely, including its space in the layout.
Which HTML tag is used to define the largest heading?
A) <h1>
B) <h2>
C) <h3>
D) <header>
Answer: A
Explanation: The <h1> tag is used to define the largest heading in HTML.
Which JavaScript method is used to parse a string as an integer?
A) parseInt()
B) parseString()
C) toInteger()
D) integer()
Answer: A
Explanation: The parseInt() method is used to parse a string and return an integer.
Which of the following is the correct syntax to center a block element in CSS?
A) text-align: center;
B) margin: auto;
C) position: center;
D) align-items: center;
Answer: B
Explanation: The margin: auto; property is used to center a block-level element horizontally in CSS.
Which JavaScript method is used to trigger an alert box with a message?
A) alert()
B) message()
C) showAlert()
D) popUp()
Answer: A
Explanation: The alert() method is used to display an alert box with a message.
Which of the following HTML tags is used to define an ordered list?
A) <ul>
B) <ol>
C) <list>
D) <li>
Answer: B
Explanation: The <ol> tag is used to define an ordered (numbered) list in HTML.
Which of the following is the correct syntax for an external JavaScript file?
A) <script src=”script.js”>
B) <javascript src=”script.js”>
C) <js src=”script.js”>
D) <link src=”script.js”>
Answer: A
Explanation: The correct syntax to link an external JavaScript file is using the <script src=”script.js”> tag.
Which CSS property is used to create space between an element’s border and its content?
A) margin
B) padding
C) border-spacing
D) gap
Answer: B
Explanation: The padding property creates space between an element’s border and its content.
Which of the following is a valid way to define a JavaScript function?
A) function myFunction() {}
B) func myFunction() {}
C) function = myFunction() {}
D) define function myFunction() {}
Answer: A
Explanation: The correct syntax to define a JavaScript function is function myFunction() {}.
Which HTML element is used to display an image?
A) <img>
B) <picture>
C) <image>
D) <src>
Answer: A
Explanation: The <img> element is used to display images in an HTML document.
What does the float property do in CSS?
A) Aligns the element to the left or right of its container
B) Removes the element from the flow of the document
C) Adds space between elements
D) Defines the background color of an element
Answer: A
Explanation: The float property is used to align an element to the left or right of its container, allowing other elements to flow around it.
Which of the following CSS properties is used to change the background color of an element?
A) background-color
B) bg-color
C) color
D) border-color
Answer: A
Explanation: The background-color property is used to set the background color of an element in CSS.
Which of the following HTML tags is used to define a division or section in a document?
A) <div>
B) <section>
C) <article>
D) <span>
Answer: A
Explanation: The <div> tag is used to define a division or section within an HTML document, typically used for grouping content.