how to use simple P5js FOR loop to make pattern

trying to help a middle school child prepare for a test on P5js. the topic is for loops and making patterns using: push(), pop(), translate(), rotate(), scale()

I wasn’t able to find an easy sample code to demonstrate this.

Can someone post a simple code snippet that uses for loops (I’m assuming two nested loops) to create a pattern like attached? enter image description here

Sequelize – users is not associated to tweets

I have some issues when I try to getTweets from database. That’s my models

models/UserModel.js

import { Sequelize } from "sequelize";
import db from "../config/database.js";

const { DataTypes } = Sequelize;

const User = db.define(
  "users",
  {
    name: {
      type: DataTypes.STRING,
    },
    email: {
      type: DataTypes.STRING,
      unique: true,
    },
    password: {
      type: DataTypes.STRING,
    },
    refresh_token: {
      type: DataTypes.TEXT,
    },
  },
  {
    freezeTableName: true,
  }
);

export default User;

and this is models/TweetModel.js

import { Sequelize } from "sequelize";
import db from "../config/database.js";
const { DataTypes } = Sequelize;

const Tweet = db.define(
  "tweets",
  {
    userId: {
      type: DataTypes.INTEGER,
      allowNull: false,
    },
    title: {
      type: DataTypes.STRING,
    },
    topic: {
      type: DataTypes.STRING,
    },
    content_tweet: {
      type: DataTypes.TEXT,
    },
  },
  {
    freezeTableName: true,
  }
);

export default Tweet;

and this is my association in models/index.js

import { Sequelize } from "sequelize";
import db from "../config/database.js";
const { DataTypes } = Sequelize;

const Tweet = db.define(
  "tweets",
  {
    userId: {
      type: DataTypes.INTEGER,
      allowNull: false,
    },
    title: {
      type: DataTypes.STRING,
    },
    topic: {
      type: DataTypes.STRING,
    },
    content_tweet: {
      type: DataTypes.TEXT,
    },
  },
  {
    freezeTableName: true,
  }
);

export default Tweet;

I want to get Tweets like:

{
  "id": 1,
  "userId":
  {
   name: 'Name User'
  }
  "title": "Title",
  "topic": "Topic",
  "content_tweet": "Content",
  "createdAt": "2023-11-19T14:46:04.000Z",
  "updatedAt": "2023-11-19T14:46:04.000Z"
}

In controller i try like this

await Tweet.findAll({
      include: [{ model: User, attributes: ["name"] }],
    });

but getting message
users is not asscociated to tweets!. I am not using sequlize-cli to handle model. The question is why my association not works?

My expection is my code is working but isn’t

Using Webpack for browser extension problems accessing DOM elements of HTML

I’m creating a browser extension for firefox and originally had an issue about using require() statements in JS. I fixed this issue using Webpack to bundle the code and give me access to those statements. I am now having an issue with trying to use document.getElementByID selectors for the DOM elements. I cannot seem to access these elements at all.

My JS code looks like this:

document.addEventListener("DOMContentLoaded", function () {

    const button = document.getElementById('#spellButton');
    button.addEventListener("click", function () {
        const paragraph = document.getElementById("spellResult");
        paragraph.textContent = "Hello!";
    });

});

My HTML looks like this:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="popup.css">

  <script src="main.js" type="module"></script>

  <title>Document</title>


</head>

<body>
  <header>
    <p>
      Site Spy
    </p>
  </header>

  <main class="safteyCheck">
    <u>
      Current Site:
    </u>
    <p id="siteURL"> a</p>
    <p style="color: grey;" id="result">
      UNKOWN
    </p>
    <button id="scanButton">
      Scan Site
    </button>
    <p id="spellResult"></p>
    <button id="spellButton">
      Scan Site
    </button>

  </main>

  <footer>
    <p>&copy; 2023 EggsCorp</p>
  </footer>
</body>

</html>

My package.json:

{
  "name": "webpack-demo",
  "version": "1.0.0",
  "description": "",
  "private": true,
  "scripts": {
    "test": "echo "Error: no test specified" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@webpack-cli/generators": "^3.0.7",
    "webpack": "^5.89.0",
    "webpack-cli": "^5.1.4"
  },
  "dependencies": {
    "typo-js": "^1.2.3"
  }
}

I am new to webpack & extension development so forigve me if there is an obvious error, I cannot figure this out at the moment. What could the issue be or a work around?

I expected to be able to use DOM elements in Webpack but have possibly misunderstood what I need to do.

Uncaught SyntaxError C:Usersnayyealumni-bclientsrcApp.js:1 import “./App.css”;

I am making a react application for the first time. I am running app.js on the client folder and its returning the following error:

C:Program Filesnodejsnode.exe .clientsrcApp.js
Uncaught SyntaxError C:Usersnayyealumni-bclientsrcApp.js:1
import "./App.css";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1153:20)
    at Module._compile (node:internal/modules/cjs/loader:1205:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at executeUserEntryPoint (node:internal/modules/run_main:83:12)
    at <anonymous> (node:internal/main/run_main_module:23:47)
Process exited with code 1

This is my app.js file:

import "./App.css";
import axios from "axios";
import { useEffect } from "react";

function App() {
  useEffect(() => {
    axios.get("http://localhost:3001/users").then((response) => {
      console.log(response.data);
    });
  }, []);

  return (
    
    <div className="App">
    
    </div>
    
  );
}

export default App;

My index.js file in the server folder is running without any issues and i tested it on postman as well.

Incorrect auto increment using fetch POST after manually deleted data from table [duplicate]

i created REST API and website which is using it. There is database and inside it table with columns id and room. Id have turned on auto increment. I have a button that create ticket by fetch and method post. Inside body there is only room number “101”. I deleted manually tickets from table that i created before by pressing button and my tickets table is empty. But when i press button then it doest create ticket with is 1… there is id 91, 92… I dont know how to reset this counting. Please help me. Sorry for my English. Here is my fetch script that create ticket.

`<script>
const button = document.getElementById('button');
button.addEventListener('click', function(e){
e.preventDefault();
const room = {
room: 101,
}
console.log(room)
fetch('http://localhost/tickets', {
method: "POST",
headers: {
'Content-type': 'application/json'
},
body: JSON.stringify(room),
})
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.log(err));
})
function visitPage(){
window.location='room_101.html';
return room;
}
</script>`

I dont know how to solve the problem. Is it api problem or js? I dont know what to do.

Hey all, I’m a total noob. I gotta know, Is this forum still a viable source? [closed]

yes it’s true, I am a noob… but I’m committed to my goals. So, I’m trying to consume as much information as I possibly can.

Is Stack overflow still a viable source for knowledge? Is there a ‘video’ to help a new guy walk through how to benefit from investing some attention here, versus alternatives?

This site seems a little intimidating (with it’s many rules). I tried to answer a question that I thought I knew a possible solution to, and then a warning popped up to confirm that I thanked the person, and…. paragraphs worth of instructions. So I went to edit my answer some, but decided I was proper in my response, so I went back to post it again and somehow, my post was missing the 1st sentence from my answer, so I just deleted it.

TBH, I’m having a good time with AI, but I’m hoping for a more human experience, in my exchange of thought.

Again I ask, Is Stack overflow still a viable source for knowledge?

See, even now, I was done with my post. But I’m forced to be verbose? So, in that case, I will state here, I hope I can get some real answers to my post. I AM hopeful. I bid you all a Great Day!

Defining variable inside object Javascript

I have this code

var authCode = $("#authcode_text").val();
            var settings = {
                "url": "https://3aasdf.asdas.app/v4/test/api/serialnumber/test/query",
                "method": "POST",
                "timeout": 0,
                "headers": {
                    "API_KEY": "34ASD-cf43-4cd5-4333-30SJFFS",
                    "Content-Type": "application/json"
                },
                "data": JSON.stringify({
                    "serialNumber": authCode --> **it generates an error here** 
                }),
            };

Referenceerror “authCode” is not defined

Can someone help me why it’s showing an error?

Issue with dynamically drawing multiple svgs on image with onMouse events due to viewport positioning

everybody! Right now I am struggling with a new project of mine. The goal is to have an image rendered as a React component and then drawing boxes with svg on top of it. To achieve that I have set positioning to absolute in the respective css file. I want to attach a onMouseOver function to each of the boxes drawn and this is where I have an issue:

I need to move the viewPort of the svg to only the box drawn because otherwise the onMouseOver function will trigger as soon as I hover over the image as well as when I enter the rectangle. This is because I can only attach the function to the svg viewPort not to the rectangle directly. Whenever I move the viewPort of the SVG this setting will be “ignored” due to the absolute positioning in css. As the rectangle will be drawn dynamically based on fetched data (not implemented right now) I cannot hardcode the position in css.

Please find the code sandbox here: Codesandbox

And here is the code to the sample:

import React from "react";
import { SVGProps } from "react";

const SvgComponent = (props: SVGProps<SVGSVGElement>) => (
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 750 2050" {...props}>
    <rect
      x={190}
      y={300}
      width={300}
      height={200}
      style={{
        fill: "none",
        stroke: "darkred",
        strokeWidth: "10",
        pointerEvents: "visible",
      }}
    />
  </svg>
);

export default () => (
  <div>
    <SvgComponent
      onMouseOver={() => {
        console.log("Mouse over detected");
      }}
    />
    <img src="https://wallup.net/wp-content/uploads/2016/04/06/338054-landscape-Sun.jpg" />
    <style>
      {`
      svg {
        position: absolute;
        z-index: 0:
      }
    `}
    </style>
  </div>
);

I tried to condense the problem as much as possible so that it easy to reproduce. Thanks to everybody who can help me out on this one!

Relative path dosent work when trying to load json from a local file

const exploreRivers = () => {
  useEffect(()=>{
    fetch('../assets/stationData.json')
      .then((response) => response.json())
      .then((json) => console.log(json));
  },[])

I am fetching the local json data like showed above, the json data format is like this:

"[n  {n    "stationName": "Femsj\u00f8",n    "stationId": "1.15.0",n    "river": "Haldenvassdraget",n    "kommune": "Halden",n    "kommuneNumber": "3001",n    "fylke": "Viken"n  },n  {n    "stationName": "Lierelv",n    "stationId": "1.200.0",n    "river": "Haldenvassdraget",n    "kommune": "Aurskog-H\u00f8land",n    "kommuneNumber": "3026",n    "fylke": "Viken"n  },n  {n    


My file structure looks like this: image
.

Json data is inside stationData.json

In the error message it looked like my program is trying to fetch from a full url, error message follows as link right under :

enter image description here error message

I tried to change the path from relative to absolute, but still no luck.

TR mouse hover tooltip table row

I am trying to find a way to have a mouseover tooltip that follows the mouse when a TABLE ROW is hovered.

I am able to get a working example for the TD but not for the TR.

Therefore I need to create a tooltip for each TD on a row in order to get the desired result/effect.

I am sure there must be a way to have the tooltip applied to a TR instead of the TD.

I have scoured the internet and I have seen similar questions without any actual results.

TLDR- CSS, Javascript TR hover tooltip that follows mouse.

mousedown event works great on codepen but one element fires twice when export html

I’m using inline svg elements as buttons, binding mousedown,up,touchstart,end events using same method.
On codepen everything works as (I) expected. But when export to html, two element fire mouse down event twice.
codepen link: https://codepen.io/Birhan-Takran/pen/PoVqjqV
plain html link: https://modelci.net/js

All buttons are svg elements. Path and/or group elements.
All events binding in init() function.

mousedown event hadles here ( init() );

document.addEventListener("mousedown",function(e){mdwn=true; Dugmeler(e);},false);

Twice fired ojects do this ( function Dugmeler() means buttons );

if (e.target.closest("#sr2")) {Kanal1.Yon = (Kanal1.Yon==0)?1:0;ServoYon();return;}
if (e.target.closest("#sr1")) {Kanal3.Yon = (Kanal3.Yon==0)?1:0;ServoYon();return;}

function ServoYon (means Servo Direction) changes clicked servoicon orientation.

all other clickables working same approach and working fine. Tested both codepen and plain html with desktop and mobile using firefox, opera, chrome.

Clicking white area closes modal, upper right question mark opens modal. (They uses same coding and never fires twice)

I added an alert at the beginning of the function to detect double firing.
Thank you to everyone who is interested.

I’d tried direct binding event to sr1 and sr2 object instead of target.closest method, but it did not solve the problem and caused problems in mobile/desktop functionality.

NOTE : My question is not about the codepen, but about the mousedown event that fires twice. There are many multi event questions on stackoverflow, but they do not resemble my problem.

JavaScript Infinite Slider

I’m experiencing an issue with the slider. When scrolling to the right, it halts at the right edge. Despite having utilized a similar structure in a previous instance where it worked correctly, in this case, the scrolling stops at the right edge.

function infiniteScroll() {
  const { scrollLeft, scrollWidth, offsetWidth } = carousel;
  if (scrollLeft === 0) {
    carousel.classList.add("no-transition");
    carousel.scrollTo({ left: scrollWidth - 2 * offsetWidth });
    carousel.classList.remove("no-transition");
  } else if (Math.ceil(scrollLeft) >= scrollWidth - offsetWidth) {
    carousel.classList.add("no-transition");
    carousel.scrollTo({ left: offsetWidth });
    carousel.classList.remove("no-transition");
  }
}

I attempted to modify the scrolling conditions to reach the right edge, but the slider is not detecting the right edge.

Math.ceil(scrollLeft) >= scrollWidth - offsetWidth