1+ const menuEmail = document . querySelector ( ".navbar-email" ) ;
2+ const desktopMenu = document . querySelector ( ".desktop-menu" ) ;
3+ const burgerMenu = document . querySelector ( ".menu" ) ;
4+ const mobilMenu = document . querySelector ( ".mobile-menu" ) ;
5+ const menuCarritoIcon = document . querySelector ( ".navbar-shopping-cart" ) ;
6+ const aside = document . querySelector ( ".product-detail" ) ;
7+ const cardsContainer = document . querySelector ( ".cards-container" ) ;
8+
9+ menuEmail . addEventListener ( "click" , toggleDesktopMenu ) ;
10+ burgerMenu . addEventListener ( "click" , toggleMobileMenu ) ;
11+ menuCarritoIcon . addEventListener ( "click" , toggleCarritoAside ) ;
12+
13+ function toggleDesktopMenu ( ) {
14+ const isAsideClose = aside . classList . contains ( "inactive" ) ;
15+ if ( ! isAsideClose ) {
16+ aside . classList . add ( "inactive" ) ;
17+ }
18+ desktopMenu . classList . toggle ( "inactive" ) ;
19+ }
20+
21+ function toggleMobileMenu ( ) {
22+ const isAsideClose = aside . classList . contains ( "inactive" ) ;
23+ if ( ! isAsideClose ) {
24+ aside . classList . add ( "inactive" ) ;
25+ }
26+ mobilMenu . classList . toggle ( "inactive" ) ;
27+ }
28+
29+ function toggleCarritoAside ( ) {
30+ const isMobileMenuClose = mobilMenu . classList . contains ( "inactive" ) ;
31+ if ( ! isMobileMenuClose ) {
32+ mobilMenu . classList . add ( "inactive" ) ;
33+ }
34+ aside . classList . toggle ( "inactive" ) ;
35+ }
36+
37+ const productList = [ ] ;
38+ productList . push ( {
39+ name : "Producto 1" ,
40+ price : 100 ,
41+ image :
42+ "https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" ,
43+ } ) ;
44+ productList . push ( {
45+ name : "Producto 2" ,
46+ price : 120 ,
47+ image :
48+ "https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" ,
49+ } ) ;
50+ productList . push ( {
51+ name : "Producto 3" ,
52+ price : 130 ,
53+ image :
54+ "https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" ,
55+ } ) ;
56+ productList . push ( {
57+ name : "Producto 4" ,
58+ price : 140 ,
59+ image :
60+ "https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" ,
61+ } ) ;
62+ productList . push ( {
63+ name : "Producto 5" ,
64+ price : 150 ,
65+ image :
66+ "https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" ,
67+ } ) ;
68+ productList . push ( {
69+ name : "Producto 6" ,
70+ price : 160 ,
71+ image :
72+ "https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" ,
73+ } ) ;
74+ productList . push ( {
75+ name : "Producto 7" ,
76+ price : 170 ,
77+ image :
78+ "https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" ,
79+ } ) ;
80+ productList . push ( {
81+ name : "Producto 8" ,
82+ price : 180 ,
83+ image :
84+ "https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" ,
85+ } ) ;
86+
87+ function renderProductList ( arr ) {
88+ for ( product of arr ) {
89+ const productCard = document . createElement ( "div" ) ;
90+ productCard . classList . add ( "product-card" ) ;
91+
92+ const productImg = document . createElement ( "img" ) ;
93+ productImg . setAttribute ( "src" , product . image ) ;
94+
95+ const productInfo = document . createElement ( "div" ) ;
96+ productInfo . classList . add ( "product-info" ) ;
97+
98+ const productInfoDiv = document . createElement ( "div" ) ;
99+
100+ const productPrice = document . createElement ( "p" ) ;
101+ productPrice . innerText = "$" + product . price ;
102+
103+ const productName = document . createElement ( "p" ) ;
104+ productName . innerText = product . name ;
105+
106+ const productInfoFigure = document . createElement ( "figure" ) ;
107+ const productImgCart = document . createElement ( "img" ) ;
108+
109+ productImgCart . setAttribute ( "src" , "./icons/bt_add_to_cart.svg" ) ;
110+ productInfoFigure . appendChild ( productImgCart ) ;
111+ productInfoDiv . appendChild ( productPrice ) ;
112+ productInfoDiv . appendChild ( productName ) ;
113+ productInfo . appendChild ( productInfoDiv ) ;
114+ productInfo . appendChild ( productInfoFigure ) ;
115+ productCard . appendChild ( productImg ) ;
116+ productCard . appendChild ( productInfo ) ;
117+
118+ cardsContainer . appendChild ( productCard ) ;
119+ }
120+ }
121+
122+ renderProductList ( productList ) ;
0 commit comments