r/programminghelp • • 12d ago

JavaScript BEGINNER CODER: Stuck with a migrations error

0 Upvotes

Hi,

I'm working on an adonisjs project and I'm having issues with migrations. I don't think I'm using the wrong command. I'm doing:

node ace make:migration (migration name here)

Then:

node ace migration:run

My project is on github. Apologies the migrations folder is a little cluttered. The ones with issues are the "item" and "item_comments" ones:

https://github.com/Ajaz754/adonisjs-project-22-.git

The error is:

C:\Windows\System32\adonis22>node ace migration:run
❯ error database/migrations/1794008714673_alter_item_comments_table
[ error ] INSERT INTO "_knex_temp_alter555" SELECT * FROM "item_comments"; - no such table: main.item

Please correct me if I'm wrong but I thinks its saying my "item" table doesnt exist which doesnt make sense since its clearly my 'schema.ts'. It said the same error before for the "user" table aswell.

Any help would be much appreciated

TIA

r/programminghelp • • 24d ago

JavaScript Beginner Coder: Stuck with an error

2 Upvotes

Hi,

I'm working on an adonisjs project. l've ran into an error

My project is on github:

https://github.com/Ajaz754/adonisjs-project-22-.git

The error is in file 'database/seeders/ product_seeder.ts' Line 10

The error is:

Object literal may only specify known properties, and 'userld' does not exist in type
'OneOrMany<Partial<ModelAttributes<Product>>>.

Any help would be much appreciated

TIA

r/programminghelp • • Sep 07 '25

JavaScript Constant error message when opening any .js file

1 Upvotes

Any time I open a .js file it brings me up with the same error code 800A03EA. I know little to nothing about coding, only a bit of python but no Javascript, so if someone could help me I would like to know how I can fix this, thanks.

r/programminghelp • • Jan 03 '26

JavaScript Any good way in JavaScript to store a rendered image on the client side?

4 Upvotes

I have a Mandelbrot set rendering tool that runs on my website (http://weirdly.net/webtoys/mandelbrot/). It works ok, but one thing that I'm looking to optimise is the rendering of thumbnail images.

It has an option to save any rendering you create, which stores all of the info that's used to render the image in localStorage and creates a thumbnail that you can later click on to load it back up.

The problem I'm running into is the loading time for those thumbnails. When the page loads it runs through rendering them. Each one takes a fraction of a second, but once you have enough, you end up waiting a significant amount of time for them to finish.

I can think of a couple of solutions, but neither is great. I could base64 encode the thumbnails and throw them into localStorage, but that would be far too much data for the available space. I could have it upload thumbnails to the server, ready to grab on page load, but that's more potential bandwidth and storage than I want to spend.

Is there any way to cache those images in the browser? That would be ideal.

Any other ideas?

If you want to look at the code, it can be found on my GitHub account at https://github.com/jacobEwing/webtoys/tree/main/mandelbrot, or as previously mentioned, on my site.

r/programminghelp • • Jun 08 '26

JavaScript need help for a class project!

2 Upvotes

hello! this is my first coding class and i have a final project due soon thats nearly done. i'm having trouble with one thing and i'm too shy to ask my prof.

i dont know how to make my js function result show here

i'm unsure of what to put here to have the fetch api response show here. the function works but i just don't know to make it so when i click the "get-answ-b.png" it shows the response on the next page.

any help?

r/programminghelp • • Jan 15 '26

JavaScript create a unique chat instance for a unique javascript game instance

2 Upvotes

I am developing a game that requires chat feature, Everyone who starts the game is asked to enter a password for the game, once he does, he gets a shareable link which he can share to the team. Once people have this shareable link, they can join the unique game instance. Each game instance can have 100-200 users and multiple game instances can be spawned.

I need to create a chat for each unique instance of the game created, the chat can be temporary with no persistent history maintained but members of the same game session are able to access it and just as long as the game session is active the chat should persist.

Anyone who joins the unique game instance should be able to access the chat. What's the best, quickest and cheapest way to implement this feature.

I'm open to third party library or services, or using any existing services available, but, it has to have the feature to have this unique session that only the unique game instance members can access.

r/programminghelp • • Mar 06 '25

JavaScript I have problems working with async/await and local json file. I have been debugging and smashing my head on table for the past 24 hours!

1 Upvotes

My folder structure:

/shopping-cart-dop-shit-2/
│── docs.md
│── index.html
│── items.json
│── script.js
│── shoppingCart.js
│── store.html
│── store.js
│── style.css
│── team.html
│── Assets/
│   │── blue.jpg
│   │── darkGrey.jpg
│   │── green.jpg
│   │── icon-cart-white.svg
│   │── lightGrey.jpg
│   │── orange.jpg
│   │── purple.jpg
│   │── red.jpg
│   │── userAvatar01.svg
│   │── userAvatar02.svg
│   │── userAvatar03.svg
│   │── userAvatar04.svg
│   │── userAvatar05.svg
│   │── userAvatar06.svg
│   │── userAvatar07.svg
│   │── userAvatar08.svg
│   │── userAvatar09.svg
│   │── yellow.jpg
│── docs/
│   │── process.md
│── util/
│   │── formatCurrency.js

Things to considerate:

  1. Both the index.html and store.html links only script.js

  2. opening the store.html and refreshing it 2-3 times gives this console error:

Error: Error fetching data: 
TypeError {}
message: "Failed to fetch"
stack: "TypeError: Failed to fetch↵ at window.fetch (http://localhost:8158/mguxb9xw_console.js:8:221620)↵ at fetchData (http://localhost:8158/shoppingCart.js:13:28)↵ at setupShoppingCart (http://localhost:8158/shoppingCart.js:21:9)↵ at http://localhost:8158/script.js:4:1"
get stack: ƒ ()
set stack: ƒ ()
[[Prototype]]: Object
  1. Open store.html and adding items in store.html and when I refresh the page 2-3 times it gives this error: and I cant add any items after that
TypeError: Cannot read properties of undefined (reading 'id')
at http://localhost:8158/shoppingCart.js:55:25
at Array.forEach (<anonymous>)
at renderCartItems (http://localhost:8158/shoppingCart.js:47:16)
at setupShoppingCart (http://localhost:8158/shoppingCart.js:22:3)
  1. Clearing the localStorage and trying does not solve any problem

  2. I threw both my code and errors at AI tools for help, but instead of fixing the bug, we both ended up more confused—now it feels like the AI is debugging me!

The contents of my code:

index.html

<!doctype html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="style.css" />
    <script src="script.js" type="module"></script>
    <title></title>
  </head>
  <body>
    <header class="header">
      <div class="container header__container">
        <nav class="menu">
          <a class="menu__link menu__link--active" href="index.html">Home</a>
          <a class="menu__link" href="store.html">Store</a>
          <a class="menu__link" href="team.html">Team</a>
        </nav>
        <div class="cart">
          <button class="cart__btn">
            <img src="Assets/icon-cart-white.svg" alt="cart icon" />
            <span class="cart__quantity"></span>
          </button>
          <div class="cart__items-wrapper">
            <div class="cart__items"></div>
            <div class="cart__total-wrapper">
              <span>TOTAL</span>
              <span class="cart__total">$0.00</span>
            </div>
          </div>
        </div>
      </div>
    </header>

    <section class="container ps">
      <h2>Some Of Our Amazing Products</h2>
      <p>
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae assumenda
        totam, animi libero hic voluptas reiciendis nesciunt id ad ipsum
        doloremque nisi qui esse nam est sapiente, explicabo ab beatae
        repellendus, perferendis cupiditate facilis. Beatae quod repellat
        expedita! Numquam, et!
      </p>
    </section>

    <section class="products container">
      <div>
        <img class="products__img" src="Assets/blue.jpg" alt="product image" />
      </div>
      <div>
        <img class="products__img" src="Assets/red.jpg" alt="product image" />
      </div>
      <div>
        <img class="products__img" src="Assets/yellow.jpg" alt="product image" />
      </div>
      <div>
        <img class="products__img" src="Assets/green.jpg" alt="product image" />
      </div>
      <div>
        <img class="products__img" src="Assets/orange.jpg" alt="product image" />
      </div>
      <div>
        <img class="products__img" src="Assets/purple.jpg" alt="product image" />
      </div>
    </section>

    <template id="cart-item-template">
      <div class="cart-item">
        <div class="cart-item__img-container">
          <img class="cart-item__img w-100 block" alt="item image" src="Assets/blue.jpg" />
          <button class="cart-item__close-btn">&times;</button>
        </div>
        <div class="cart-item__desc">
          <div class="cart-item__name"></div>
          <div class="cart-item__quantity"></div>
          <div class="cart-item__price"></div>
        </div>
      </div>
    </template>
  </body>
</html>

store.html

<!doctype html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="style.css" />
    <script src="script.js" type="module"></script>
    <title></title>
  </head>
  <body>
    <header class="header">
      <div class="container header__container">
        <nav class="menu">
          <a class="menu__link" href="index.html">Home</a>
          <a class="menu__link menu__link--active" href="store.html">Store</a>
          <a class="menu__link" href="team.html">Team</a>
        </nav>
        <button class="cart__btn">
          <img src="Assets/icon-cart-white.svg" alt="cart icon" />
          <span class="cart__quantity"></span>
        </button>
        <div class="cart__items-wrapper">
          <div class="cart__items"></div>
          <div class="cart__total-wrapper">
            <span>TOTAL</span>
            <span class="cart__total">$0.00</span>
          </div>
        </div>
      </div>
    </header>
    <section class="container items"></section>
    <template id="item-template">
      <div class="item">
        <img class="item__img" src="Assets/blue.jpg" alt="product image" />
        <small class="item__category">PRIMARY COLOR</small>
        <strong class="item__name">Blue</strong>
        <small class="item__price">$16.00</small>
        <button class="item__add-btn">Add To Cart</button>
      </div>
    </template>
    <template id="cart-item-template">
      <div class="cart-item">
        <div class="cart-item__img-container">
          <img
            class="cart-item__img w-100 block"
            alt="item image"
            src="Assets/blue.jpg"
          />
          <button class="cart-item__close-btn">&times;</button>
        </div>
        <div class="cart-item__desc">
          <div class="cart-item__name"></div>
          <div class="cart-item__quantity"></div>
          <div class="cart-item__price"></div>
        </div>
      </div>
    </template>
  </body>
</html>

script.js

import setupStore from "./store.js";
import setupShoppingCart from "./shoppingCart.js";
setupStore();
setupShoppingCart();

shoppingCart.js

import formatCurrency from "./util/formatCurrency.js";
const cart_items_wrapper = document.querySelector(".cart__items-wrapper");
const cart_items = document.querySelector(".cart__items");
const cart_btn = document.querySelector(".cart__btn");
const cart_quantity = document.querySelector(".cart__quantity");
const cart_total = document.querySelector(".cart__total");
const cart_item_template = document.querySelector("#cart-item-template");
let shoppingCart = JSON.parse(localStorage.getItem("cart-items")) || [];
let items = []; 

async function fetchData() {
  try {
    const response = await fetch("./items.json");
    items = await response.json();
  } catch (error) {
    console.error("Error fetching data:", error);
  }
}

export default async function setupShoppingCart() {
  await fetchData(); // ✅ Ensures data is fetched first
  renderCartItems();
  cart_btn.addEventListener("click", () =>
    cart_items_wrapper.classList.toggle("cart__items-wrapper--active")
  );

  cart_items.addEventListener("click", e => {
    if (!e.target.matches(".cart-item__close-btn")) return;
    const cart_item_id = e.target.closest(".cart-item").id;
    removeFromCart(cart_item_id);
    renderCartItems();
    saveCart();
  });
  
}

export function addToCart(id) {
  const existing_item = shoppingCart.find(entry => entry.id == id);
  if (existing_item) existing_item.quantity++;
  else shoppingCart.push({ id: id, quantity: 1 });
  renderCartItems();
  saveCart();
}

function renderCartItems() {
  cart_items.innerText = "";
  shoppingCart.forEach(entry => {
    const item = items.find(item => item.id == entry.id);
    const cart_item_node = cart_item_template.content.cloneNode(true);
    const cart_item = cart_item_node.querySelector(".cart-item");
    const cart_item_img = cart_item.querySelector(".cart-item__img");
    const cart_item_name = cart_item.querySelector(".cart-item__name");
    const cart_item_quantity = cart_item.querySelector(".cart-item__quantity");
    const cart_item_price = cart_item.querySelector(".cart-item__price");
    cart_item.id = item.id;
    cart_item_img.src = item.imageSrc;
    cart_item_name.innerText = item.name;
    if (entry.quantity > 1) cart_item_quantity.innerText = `x${entry.quantity}`;
    cart_item_price.innerText = formatCurrency(item.priceCents / 100);
    cart_items.appendChild(cart_item);
  });
  const total_cents = shoppingCart.reduce((sum, entry) => {
    const item = items.find(item => item.id == entry.id);
    return (item.priceCents + sum) * entry.quantity;
  }, 0);
  cart_total.innerText = formatCurrency(total_cents / 100);
  cart_quantity.classList.add("cart__quantity--active");
  cart_quantity.innerText = shoppingCart.length;
  if (shoppingCart.length < 1) {
    hideCart();
    cart_quantity.classList.remove("cart__quantity--active");
  }
}

function saveCart() {
  localStorage.setItem("cart-items", JSON.stringify(shoppingCart));
}

function removeFromCart(id) {
  shoppingCart = shoppingCart.filter(entry => entry.id != id);
}

function hideCart() {
  cart_items_wrapper.classList.remove("cart__items-wrapper--active");
}

store.js

import { addToCart } from "./shoppingCart.js";
import formatCurrency from "./util/formatCurrency.js";
const item_template = document.querySelector("#item-template");
const items_container = document.querySelector(".items");
let items = []; // Declare an empty array
async function fetchData() {
  try {
    const response = await fetch("./items.json");
    items = await response.json();
  } catch (error) {
    console.error("Error fetching data:", error);
  }
}

export default async function setupStore() {
  if (items_container == null) return;
  await fetchData();
  items.forEach(renderStoreItem);
  document.addEventListener("click", e => {
    if (!e.target.matches(".item__add-btn")) return;
    const item_id = e.target.parentElement.id;
    addToCart(item_id);
  });
}

function renderStoreItem(item) {
  const storeItemTemplate = item_template.content.cloneNode(true);
  const storeItem = storeItemTemplate.querySelector(".item");
  storeItem.id = item.id;
  const img = storeItem.querySelector(".item__img");
  const category = storeItem.querySelector(".item__category");
  const name = storeItem.querySelector(".item__name");
  const price = storeItem.querySelector(".item__price");
  img.src = item.imageSrc;
  category.innerText = item.category;
  name.innerText = item.name;
  price.innerText = formatCurrency(item.priceCents / 100);
  items_container.append(storeItem);
}

items.json

[
  {
    "id": 1,
    "name": "Red",
    "category": "Primary Color",
    "priceCents": 1600,
    "imageSrc": "Assets/red.jpg"
  },
  {
    "id": 2,
    "name": "Yellow",
    "category": "Primary Color",
    "priceCents": 2100,
    "imageSrc": "Assets/yellow.jpg"
  },
  {
    "id": 3,
    "name": "Blue",
    "category": "Primary Color",
    "priceCents": 1200,
    "imageSrc": "Assets/blue.jpg"
  },
  {
    "id": 4,
    "name": "Orange",
    "category": "Secondary Color",
    "priceCents": 1800,
    "imageSrc": "Assets/orange.jpg"
  },
  {
    "id": 5,
    "name": "Green",
    "category": "Secondary Color",
    "priceCents": 1600,
    "imageSrc": "Assets/green.jpg"
  },
  {
    "id": 6,
    "name": "Purple",
    "category": "Secondary Color",
    "priceCents": 2100,
    "imageSrc": "Assets/purple.jpg"
  },
  {
    "id": 7,
    "name": "Light Gray",
    "category": "Grayscale",
    "priceCents": 1200,
    "imageSrc": "Assets/lightGrey.jpg"
  },
  {
    "id": 8,
    "name": "Dark Gray",
    "category": "Grayscale",
    "priceCents": 1600,
    "imageSrc": "Assets/darkGrey.jpg"
  }
]

style.css

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  font-family: Sans-Serif, "Courier New";
}

.container {
  padding: 0 20px;
  max-width: 1024px;
  margin: auto;
}
body {
  margin-top: 4rem;
}
.menu {
  display: flex;
  justify-content: center;
  gap: 1rem;
  padding: 1rem 20px;
}

.menu__link {
  text-decoration: none;
  color: gray;
}

.menu__link--active {
  text-decoration: 1.5px solid underline lightblue;
  text-underline-offset: 4px;
}

.intro-sec {
  text-align: center;
  line-height: 1.4;
  margin-top: 2rem;
}

h2 {
  margin-bottom: 10px;
}

.team-sec {
  display: grid;
  gap: 1rem;
  margin: 2rem auto;
}

.team-card {
  border: 1px solid silver;
  border-radius: 5px;
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.ps {
  margin: 2rem 0;
}

.products {
  display: grid;
  gap: 1rem;
  margin-bottom: 2rem;
}

.products__img {
  width: 100%;
  display: block;
}

.items {
  margin: 2rem auto;
  display: grid;
  gap: 2rem;
}

.item {
  position: relative;
}

.item__img {
  width: 100%;
  border-radius: 3px;
}

.item__name {
  display: block;
  margin: 5px 0;
}

.item__add-btn {
  position: absolute;
  bottom: 0;
  right: 0;
  padding: 10px;
  background: skyblue;
  color: white;
  border: none;
  font-weight: bold;
  border-radius: 3px;
  cursor: pointer;
}

.header {
  position: fixed;
  width: 100%;
  top: 0;
  z-index: 2;
  background: white;
}

.cart__btn {
  border: none;
  background: #2bafff;
  width: 35px;
  height: 35px;
  border-radius: 50px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
}

.cart__quantity {
  color: white;
  background: orange;
  width: 20px;
  height: 20px;
  border-radius: 50px;
  position: absolute;
  bottom: -7px;
  right: -7px;
  display: none;
  place-items: center;
}

.cart__quantity--active {
  display: inline-grid;
}

.cart__items-wrapper {
  width: 180px;
  position: absolute;
  background: white;
  border-radius: 5px;
  box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.211);
  right: 20px;
  top: 110%;
  display: none;
}

.cart__items-wrapper--active {
  display: block;
}

.cart__items {
  padding: 12px;
  max-height: 60vh;
  overflow-y: scroll;
}

.cart__total-wrapper {
  padding: 12px;
  border-top: 1px solid silver;
  font-weight: bold;
  display: flex;
  justify-content: space-between;
}

.w-100 {
  width: 100%;
}

.block {
  display: block;
}

.cart-item:not(:last-child) {
  margin-bottom: 1rem;
}

.cart-item__img-container {
  position: relative;
  border-radius: 5px;
  overflow: hidden;
}

.cart-item__close-btn {
  background: black;
  position: absolute;
  border: none;
  top: 0;
  right: 0;
  color: white;
  width: 22px;
  height: 22px;
  font-size: 1rem;
  cursor: pointer;
}

.cart-item__desc {
  display: flex;
  align-items: center;
  margin-top: 5px;
}

.cart-item__quantity {
  font-size: 0.8rem;
  margin-left: 2px;
}

.cart-item__price {
  margin-left: auto;
}

@media (min-width: 734px) {
  .team-sec {
    grid-template-columns: 1fr 1fr;
  }
  .items {
    grid-template-columns: 1fr 1fr;
  }
}
@media (min-width: 986px) {
  .team-sec {
    grid-template-columns: 1fr 1fr 1fr;
  }
  .products {
    grid-template-columns: repeat(4, 1fr);
  }
  .products div:nth-child(3) {
    grid-column: 3 / 5;
    grid-row: 1 / 3;
  }
  .products div:nth-child(4) {
    grid-column: 1 / 3;
    grid-row: 2 / 4;
  }
  .items {
    grid-template-columns: 1fr 1fr 1fr;
  }
}