r/JavaScriptTips • • Jul 30 '23

The difference between redeclaring / reassigning javascript variable in 5 minutes...

3 Upvotes

Here is a short article simpling outlining the difference in mutating Var, Let and Const variables. I hope it can be of use to javascript developers at any level, please feel free to apply feedback, criticism, queries or banter! Cheers

https://thecodingapprentice.substack.com/p/reassignment-redeclaration-of-javascript


r/JavaScriptTips • • Jul 29 '23

Help for beginners.

3 Upvotes

Hello guys. I’m new to codeing and stuff but I try my best to learn. With an YouTube Tutorial I try to make a To Do List. I wrote down the code exactly like in the video but the things I write in the text field, dont get saved on the list.

Anyone has a tip for me maybe ?


r/JavaScriptTips • • Jul 27 '23

A 3 minute dive into javascript .forEach()

3 Upvotes

A short article explaining the javascript .forEach array method aimed at those who are unfamiliar with its uses or those who want to refresh their memory.

https://thecodingapprentice.substack.com/p/javascript-methods-foreach-3c7df1312cce


r/JavaScriptTips • • Jul 12 '23

How to keep the css styling after changing text content

Post image
3 Upvotes

Not sure how to keep the css code right after writing a nickname. The background colour and underline just disappear any tips, Ps: just started js 3 days ago not sure about VAR or VAL or any technical things.


r/JavaScriptTips • • Jul 10 '23

Create a simple tic tac toe game using html css javascript | How to make...

Thumbnail
youtube.com
3 Upvotes

r/JavaScriptTips • • Jul 08 '23

HELP WITH CODING ROOMS

Thumbnail
gallery
3 Upvotes

I’m doing the coding rooms free course and I’m stuck on this assignment. Instructions in the picture. Any help is appreciated


r/JavaScriptTips • • Jun 22 '23

How to Set Value of Textarea in JavaScript

3 Upvotes

Textarea tags allows users to input and edit larger blocks of text. Users can enter large types of datas text, such as comments, descriptions, or messages. In this guide, we will explore how to change the value of a textarea element using JavaScript.

HTML:

<textarea id="myTextarea">HELLO</textarea>

JS:

//Selecting textarea tag by ID
var textareaElement = document.getElementById("myTextarea");

//Setting the value in textarea
textareaElement.innerText = "This is the new text.";

We can set the value for textarea tag by using the value, innerHTML, or innerText properties dynamically.

Reac more>> 3 ways set textarea value in JS dynamically


r/JavaScriptTips • • Jun 20 '23

Authentication vs Authorization Explained for NOOBS!!

Thumbnail
youtube.com
3 Upvotes

r/JavaScriptTips • • Jun 12 '23

3 Ways To Implement Infinite Scroll

Thumbnail
medium.com
3 Upvotes

r/JavaScriptTips • • Jun 01 '23

Build an Interactive Dynamic List with HTML, CSS, and JavaScript

Thumbnail
youtube.com
3 Upvotes

r/JavaScriptTips • • May 15 '23

JavaScript Bundlers - Zero To Hero | A Webpack Tutorial For Everyone

Thumbnail
youtu.be
3 Upvotes

r/JavaScriptTips • • May 11 '23

JavaScript Promises vs Async Await vs Callback Hell (Explained in 5 minutes)

Thumbnail
youtube.com
3 Upvotes

r/JavaScriptTips • • May 11 '23

Frontend JavaScript Secrets: What Books Won’t Teach You

Thumbnail
medium.com
3 Upvotes

r/JavaScriptTips • • May 01 '23

Build a Curvy Homepage the easiest way possible using Pure CSS

Thumbnail
youtube.com
3 Upvotes

r/JavaScriptTips • • Apr 03 '23

Exploring Modern JavaScript: A Comprehensive Guide to ES6 and Beyond

Thumbnail
soshace.com
3 Upvotes

r/JavaScriptTips • • Mar 19 '23

Learn Javascript online javascript-Roadmap for beginners.

3 Upvotes

JavaScript quickly became popular because it allowed web developers to add interactivity and dynamic content to their web pages, which was previously not possible with static HTML. It was standardized as ECMAScript in 1997, and subsequent versions of JavaScript have been based on this standard.

https://www.guerillateck.com/2023/03/learn-javascript-online-javascript.html


r/JavaScriptTips • • Mar 18 '23

Making Snake Game using JavaScript

Thumbnail
youtube.com
3 Upvotes

r/JavaScriptTips • • Mar 06 '23

How to create a map with location markers 📍🗺️

Thumbnail
youtu.be
3 Upvotes

r/JavaScriptTips • • Feb 14 '23

Interesting

Post image
3 Upvotes

r/JavaScriptTips • • Jan 09 '23

A navigation web-component NPM library that enables single-page-architecture (SPA) apps using pure html, css javascript

3 Upvotes

r/JavaScriptTips • • Dec 20 '22

A beginner’s guide to using TypeScript Record Type with examples

Thumbnail
geshan.com.np
3 Upvotes

r/JavaScriptTips • • Nov 14 '22

eventlistener is not returning anything i'm really confused

3 Upvotes

Ok so in my function 'updateCartFromArray()' I managed to add an specific ID to each span that has the class 'removeFromBasket'.

The only problem is that, somehow i cant manage to add an eventlistener to each span. For some reasong when i click it it simply return nothing.

I just need to return the id of each span that has "removeFromBasket" class when i click it. But now it is simply returning NOTHING

Can you guys please help me? I dont want the solution i just want to understand what i'm doing wrong.

JS:

const data = [
    {
      id: 1,
      img: "./img/jaqueta.svg",
      nameItem: "Lightweight Jacket",
      description:
        "Adicione um pouco de energia ao seu guarda-roupa de inverno com esta jaqueta vibrante...",
      value: 100,
      addCart: "Adicionar ao carrinho",
      tag: ["Camisetas"],
    },
    {
      id: 2,
      img: "./img/gorro.svg",
      nameItem: "Black Hat",
      description:
        "O gorro Next.js chegou! Esta beldade bordada tem um ajuste confortável que garante que...",
      value: 100,
      addCart: "Adicionar ao carrinho",
      tag: ["Acessórios"],
    },
    {
      id: 3,
      img: "./img/mascara.svg",
      nameItem: "Mask",
      description:
        "Esta máscara facial durável é feita de duas camadas de tecido tratado e possui presilhas...",
      value: 40,
      addCart: "Adicionar ao carrinho",
      tag: ["Acessórios"],
    },
    {
      id: 4,
      img: "./img/camiseta_preta.svg",
      nameItem: "T-Shirt",
      description:
        "Esta t-shirt é imprescindível no seu guarda-roupa, combinando o caimento intemporal de...",
      value: 100,
      addCart: "Adicionar ao carrinho",
      tag: ["Camisetas"],
    },
    {
      id: 5,
      img: "./img/camiseta_branca.svg",
      nameItem: "Short-Sleeve T-Shirt",
      description:
        "Agora você encontrou a camiseta básica do seu guarda-roupa. É feito de um mais grosso...",
      value: 100,
      addCart: "Adicionar ao carrinho",
      tag: ["Camisetas"],
    },
    {
      id: 6,
      img: "./img/moletom.svg",
      nameItem: "Champion Packable Jacket",
      description:
        "Proteja-se dos elementos com esta jaqueta embalável Champion. Esta jaqueta de poliést...",
      value: 100,
      addCart: "Adicionar ao carrinho",
      tag: ["Camisetas"],
    },
  ];

  let itensInTheList = []


for (i = 0; i < data.length; i++) {
    div = document.createElement('div')
    div.className = "itenBox"
    div.id = data[i].id

    img = document.createElement('img')
    img.src = data[i].img

    textDiv = document.createElement('div')
    textDiv.className = "textElement"

    p = document.createElement('p')
    p.id = "type"
    p.innerHTML = data[i].tag[0]


    nameSpan = document.createElement('span')
    nameSpan.id = "name"
    nameSpan.innerHTML = data[i].nameItem

    descriptionSpan = document.createElement('span')
    descriptionSpan.id = "description"
    descriptionSpan.innerHTML = data[i].description

    priceSpan = document.createElement('span')
    priceSpan.id = "price"
    priceSpan.innerHTML = data[i].value

    basketSpan = document.createElement('span')
    basketSpan.className = "addToBasket"
    basketSpan.id = i

    basketSpan.innerHTML = "Adicionar ao carrinho"
    basketSpan.addEventListener('click', addItemToArray)

    textDiv.appendChild(p)
    textDiv.appendChild(nameSpan)
    textDiv.appendChild(descriptionSpan)
    textDiv.appendChild(priceSpan)
    textDiv.appendChild(basketSpan)
    //console.log(textDiv)

    div.appendChild(img)
    div.appendChild(textDiv)

    placeItens = document.querySelector('.itens')

    placeItens.appendChild(div)
}


function addItemToArray(event) {

    divElement = document.createElement('div')
    divElement.className = "itemInTheBasket"
    divImage = document.createElement('div')

    img = document.createElement('img')
    img.src = data[event.target.id].img
    img.height = 90

    divDescription = document.createElement('div')
    divDescription.className = "someDescription"

    spanName = document.createElement('span')
    spanName.id = "name"
    spanName.innerHTML = data[event.target.id].nameItem

    spanPrice = document.createElement('span')
    spanPrice.id = "price"
    spanPrice.innerHTML = data[event.target.id].value

    spanRemove = document.createElement('span')
    spanRemove.className = "removeFromBasket"
    spanRemove.innerHTML = "Remover do carrinho"
    
    divDescription.appendChild(spanName)
    divDescription.appendChild(spanPrice)
    divDescription.appendChild(spanRemove)
    

    divImage.appendChild(img)

    divElement.appendChild(divImage)
    divElement.appendChild(divDescription)

    itensInTheList.push(divElement)

    updateCartFromArray()
    
    
}

function updateCartFromArray(){
   emptyCart = document.querySelector('.boughtFullList')

   
    for (j = 0; j < itensInTheList.length; j++) {
      emptyCart.appendChild(itensInTheList[j])
      removeButtonPosition = itensInTheList[j].querySelector('.removeFromBasket')
      removeButtonPosition.id = j
      removeButtonPosition.addEventListener('click', console.log('ok'))
      
      

    }

}

HTML:

<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Cool Clothes</title>
    <link rel="stylesheet" href="./css/style.css">
    <script src="./js/index.js" defer></script>
    <link rel="icon" href="https://static.thenounproject.com/png/1445763-200.png">
</head>
<body>
    <header>       
            <h1>Cool Clothes</h1>
            <ul>                
                <li>Todos</li>
                <li>Acessórios</li>
                <li>Calçados</li>
                <li>Camisetas</li>
            </ul>       
    </header>
    <main>
        <div class="container">
            <div class="itens">
                
            </div>
            
            
            <div class="shoppingList">
                <div class="searchInput">
                    <input type="text" placeholder="Digite aqui sua pesquisa">
                    <button class="searchButton">Pesquisar</button>
                </div>

                <div class="headerShoppingCart">Carrinho de compras</div>

<!--
                <div class="boughtEmptyItensList">
                    <span><strong>Carrinho vazio</strong></span><span>Adicione Itens</span>
                    
                </div>

            -->
                
                 <div class="boughtFullList">
                    <!--<div class="itemInTheBasket">
                        <div><img src="./img/camiseta_branca.svg" height="85px" alt=""></div>
                        <div class="someDescription">
                            <span id="name">ok1</span>
                            <span id="price">ok2</span>
                            <span id="removeFromBasket">ok3</span>
                        </div>
                    </div>

                -->

                    
                 </div>

                 <div class="amountAndPrices">
                    <div class="amount"><span>Quantidade</span><span>90</span></div>
                    <div class="amount"><span>Preço</span><span>90</span></div>
                    
                 </div>

                 



            </div>
        </div>
    </main>

    
</body>
</html>

r/JavaScriptTips • • Oct 15 '22

Javascript Local storage

3 Upvotes

Hi, I need to set local storage in quiz to save answers after reloading site, can you help me how to do it, thank you.


r/JavaScriptTips • • Oct 15 '22

Can (a==1 && a==2 && a==3) evaluate to true in JavaScript | JavaScript Tricky Interview Question

Thumbnail
youtu.be
3 Upvotes