HTML contains a list of ul#categories .
< ul id =" categories " >
< li class =" item " >
< h2 > Animals </ h2 >
< ul >
< li > Cat </ li >
< li > Hamster </ li >
< li > Horse </ li >
< li > Parrot </ li >
</ ul >
</ li >
< li class =" item " >
< h2 > Products </ h2 >
< ul >
< li > Bread </ li >
< li > Prasley </ li >
< li > Cheese </ li >
</ ul >
</ li >
< li class =" item " >
< h2 > Technologies </ h2 >
< ul >
< li > HTML </ li >
< li > CSS </ li >
< li > JavaScript </ li >
< li > React </ li >
< li > Node.js </ li >
</ ul >
</ li >
</ ul >Write a script that:
ul#categories , ie elements li.item .li.item in ul#categories , he will find and bring the text of the element header ( <h2> tag) and the number of elements in the category (all <li> invested in it).As a result, the following messages will be displayed in the console.
Number of categories: 3
Category: Animals
Elements: 4
Category: Products
Elements: 3
Category: Technologies
Elements: 5 HTML contains an empty list ul#ingredients .
< ul id =" ingredients " > </ ul >Javascript contains an array of rows.
const ingredients = [
'Potatoes' ,
'Mushrooms' ,
'Garlic' ,
'Tomatos' ,
'Herbs' ,
'Condiments' ,
] ; Write a script that for each element of ingredients array:
<li> . Be sure to use document.createElement() method.item class.<li> for one operation into the ul.ingredients list. Write a script to create an image gallery based on an array of data. HTML contains a ul.gallery list.
< ul class =" gallery " > </ ul > Use an array of images objects to create <img> items inserted into <li> . To create the markup, use the template lines and insertAdjacentHTML() method.
const images = [
{
url : 'https://images.pexels.com/photos/140134/pexels-photo-140134.jpeg?dpr=2&h=750&w=1260' ,
alt : 'White and Black Long Fur Cat' ,
} ,
{
url : 'https://images.pexels.com/photos/213399/pexels-photo-213399.jpeg?dpr=2&h=750&w=1260' ,
alt : 'Orange and White Koi Fish Near Yellow Koi Fish' ,
} ,
{
url : 'https://images.pexels.com/photos/219943/pexels-photo-219943.jpeg?dpr=2&h=750&w=1260' ,
alt : 'Group of Horses Running' ,
} ,
] ; The counter consists of span and buttons, which should increase and decrease its value by one.
< div id =" counter " >
< button type =" button " data-action =" decrement " > -1 </ button >
< span id =" value " > 0 </ span >
< button type =" button " data-action =" increment " > +1 </ button >
</ div >counterValue , which will store the current meter value and initialize its value 0 .counterValue variable. Write a script that, when typing in the Input input#name-input ( input ), substitutes its current value in span#name-output . If the input is empty, the span should display the "Anonymous" line.
< input type =" text " id =" name-input " placeholder =" Please enter your name " />
< h1 > Hello, < span id =" name-output " > Anonymous </ span > ! </ h1 > Write a script that checks its contents about the correct number of characters entered when losing focus ( blur ).
< input
type =" text "
id =" validation-input "
data-length =" 6 "
placeholder =" Please enter 6 symbols "
/>data-length .border becomes green if the wrong number is red. To add styles, use CSS classes valid and invalid , which we have already added to the starting files of the task.
# validation-input {
border : 3 px solid # bdbdbd ;
}
# validation-input . valid {
border-color : # 4caf50 ;
}
# validation-input . invalid {
border-color : # f44336 ;
} Write a script that reacts to the change of input#font-size-control and changes the input style span#text , updating the property of font-size . As a result, by dragging the slider, the size of the text will change.
< input id =" font-size-control " type =" range " min =" 16 " max =" 96 " />
< br />
< span id =" text " > Abracadabra! </ span > Write the script of the login form.
< form class =" login-form " >
< label >
Email
< input type =" email " name =" email " />
</ label >
< label >
Password
< input type =" password " name =" password " />
</ label >
< button type =" submit " > Login </ button >
</ form >form.login-form must be processed according to submit event.alert to the fact that all fields should be filled.elements property to access the form elements.reset . Write a script that changes the colors of the element background <body> through the inline click on button.change-color and outputs color value in span.color .
< div class =" widget " >
< p > Background color: < span class =" color " > - </ span > </ p >
< button type =" button " class =" change-color " > Change color </ button >
</ div > Use getRandomHexColor to generate random color.
function getRandomHexColor ( ) {
return `# ${ Math . floor ( Math . random ( ) * 16777215 ) . toString ( 16 ) } ` ;
} Write a script for creating and cleaning the collection of elements. The user enters the number of items into input and click the Створити button, and then renders the collection. Clicking on the button Очистити , the collection of elements is cleaned.
< div id =" controls " >
< input type =" number " min =" 1 " max =" 100 " step =" 1 " />
< button type =" button " data-create > Create </ button >
< button type =" button " data-destroy > Destroy </ button >
</ div >
< div id =" boxes " > </ div > Create createBoxes(amount) function that accepts one parameter - a number. The feature creates as much <div> as it is indicated in amount and adds them to div#boxes .
<div> - 30px by 30px.getRandomHexColor function to get color. function getRandomHexColor ( ) {
return `# ${ Math . floor ( Math . random ( ) * 16777215 ) . toString ( 16 ) } ` ;
} Create destroyBoxes() function that cleanses div#boxes , thus removing all the elements created.