cant validate the input text in to do list

I am using node.js as the backend and using Axios as a frontend to handle input and output to show to do list in the sidebar but i cant validate if (input.value !== ” ) i don’t want only to show the check box in my side div also please help how i can delete to-do list after clicking the checkbox.

backend node/express :-

const express = require('express');
const cors = require('cors')
const app = express();
const path = require('path');
var arrs =[];
app.use(cors())
app.use(express.static('./font end'))
app.use(express.urlencoded({extended:false}))



app.get('/response',(req,res)=>{
    res.status(200).json({arrs});
})

app.post('/response',(req,res)=>{
const  {datas,id} = req.body;
let items = {datas,id}
arrs.push(items)
console.log(arrs)
res.status(200).sendFile(path.resolve(__dirname,'./font end/index.html'))
})


app.delete('/response',(req,res)=>{
const  {id} = req.body;
arrs=arrs.filter((e)=>e.id !== id)
res.send(arrs)
})



app.listen(5000,()=>{
    console.log('server is listening');
})

font end code :-

const show = document.querySelector('.sidebar');
const inp =document.querySelector('#datas');

const button = document.querySelector('#main-submit');
button.addEventListener('click',(e)=>{
   
})

const jappy = async ()=>{
    try{
        
    let {data} = await axios.get('http://localhost:5000/response');
    let  rez = data.arrs.map((ak)=>{
        
        return `<div class="task"><span>${ak.datas}</span><input type="checkbox" id="checkit"></div>`;
        
    })
    show.innerHTML=rez.join('');

    }
    catch(err){
    console.log(err); 
    }}

   


jappy();
           


 @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@100&display=swap');


*,::before,::after{
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
:root{
    --input-width : 300px;
    --input-color:#f5f5f5;
}

body{
font-family: 'poppins';
display: grid;
grid-template-columns: 1fr 3fr;
grid-template-rows: 300px 300px;

}

.sidebar{
grid-row: 1/3;
}

.task{
    margin-top: 10%;
    display: flex;
    justify-content: center;
    font-family: 'poppins';
    font-weight: bold;
    font-size: 18px;
    padding: 5px;
}





#checkit{
   width: 1.6rem;
   margin-left: 7px;
   cursor: pointer;
}


.task>button{
   margin-left: 10px;
   height: 30px;
   width: 30px;
    border-radius: 50%;
    border: none;
    box-shadow: none;
    cursor: pointer;
    
}

.task>button:hover{
      box-shadow: 0px 2px 2px 0px rgb(146, 146, 146);
}


.main{
margin-left: 200px;
}

form{
display: inline-flex;
margin-top: 10%;
margin-left: 10%;
    width: 350px;
    height: 350px;
    gap: 17px;
    flex-direction: column;
   justify-content: space-evenly;
   border-radius: 10%;
   border: 1px solid #D9D9D9;
   box-shadow:0px 10px 20px 0px rgba(131, 131, 131, 0.25);
    padding: 25px;
}

#datas{
width: var(--input-width);
    margin-top: 10px;
    height: 35px;
    padding: 10px;
    display: flex;
    border: none;
    background-color:var(--input-color);
    outline: none;
}

#ids{
    width: var(--input-width);
    margin-top: 10px;
    height: 35px;
    padding: 10px;
    display: flex;
    border: none;
    background-color:var(--input-color);
    outline: none;   
}


#main-submit{
    width: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    border-radius: 30px;
    background-color: #08C475;;
    border: none;
    cursor: pointer;
}


#main-submit:hover{
box-shadow:0px 3px 3px 0px rgba(158, 158, 158, 0.45);
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>To do app</title>
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>

<div class="sidebar">
    <div class="task">
    
    </div>
   
</div>

<div class="main">
        <form action="/response" method="post">
            <h1>TO DO app</h1>
            <div id="data">
            <label for="datas"><h3>item name</h3></label>
<input type="text" name="datas" id="datas" placeholder="type data">
            </div>
<div id="submit">
    <button type="submit" id="main-submit">click me</button>
</div>
 </form>
</div>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="./script.js"></script>
</body>
</html>


I tried using (input.value.trim()) in the submit button also but value blinks for moment in the side div bar and disappear

I also used delete in the backend that uses IDs but how can I adjust so i can only delete value of to do list after clicking input checkbox

How to conditionally define a field type in a Zod schema based on another field’s value?

const carSchema = z.object({
  condition: z.enum(['new', 'used']),
  ...someOtherSharedFields,
  conditionalField: z.union([z.object({foo: z.string()}), z.object({bar: z.number()})])
})

How I can implement such kind of schema so that if the ‘condition’ is ‘new’, the ‘conditionalField’ is of type { foo: string }, and if the ‘condition’ is ‘used’, the ‘conditionalField’ will be of type { bar: number }?

The solution to which I’ve come up using discriminated unions:

const someSharedSchema = ...;

const carNewSchema = someSharedSchema.extend({
  condition: z.literal('new'),
  conditionalField: z.object({foo: z.string()})
})

const carUsedSchema = someSharedSchema.extend({
  condition: z.literal('used'),
  conditionalField: z.object({bar: z.number()})
})

const carSchema = z.discriminatedUnion('condition', [carNewSchema, carUsedSchema])

Maybe there other possible solutions that might be easier to implement, especially when dealing with many (tens or more) conditions and various types of conditional fields.

ReactJS | HTML | CSS – Slider sticky images

Good morning, I really like the effect on this website (https://showcasy.framer.website/) where while scrolling the images change and they overlap. I’m using ReactJS, has anyone some ideas to get that effect? I thought about creating a big container with position: sticky and inside of this as many elements as there are the images I have with display: none. Then, I thought about using JS to get the actual scrollY and when the user gets to a specified scrollY some images gets a class named “active” that puts them display: block, but I failed miserably, so I would be grateful if anyone could help me, thanks!

Not connecting to mongo db

var express = require('express');
var router = express.Router();
const MongoClient = require('mongodb').MongoClient;


/* GET home page. */
router.get('/', function (req, res, next) {
  res.render('index', { title: 'Express' });
});

router.post("/signup", function (req, res) {
  console.log("first_name: " + req.body.first_name)
  console.log("last_name: " + req.body.last_name)
  MongoClient.connect("mongodb://localhost:27017", function(err,Client) {
  if(err) {
    console.log("ERROR");}
  else{
    console.log("CONNECTED")
  }

});
  

  res.send("HII")
})
module.exports = router;

OUTPUT
Here the data is recieved from a form but the function for checking the connection status of mongodb is not working, and no errors are showing

i am a beginer in web devolopment and dont have know much about how its connected and all.

please help me out

My code for merge sort is not working in javascript

So I have this merge sort code which works in java but the same is not working in JS. Its only sorting 1 element in 1 call. If I run the main merge function n( i.e arr.length-1) times then it sorts all the values. I want to find the mistake in this code or do I need to do some change to implement it in javascript. It looks like some recusrive steps are not fully working in tis code.



let arr=[8,7,6,5,4,3,2,1];
let sorted_arr=arr;
merge(arr,0,arr.length-1);

console.log('sorted_arr==',sorted_arr) //Array [7, 6, 5, 4, 3, 2, 1, 8]

function merge(arr,lb,hb){
 if(lb>=hb)
   return
      mid= parseInt((hb+lb)/2);
    merge(arr,lb,mid);
    merge(arr,mid+1,hb);
    sort(arr,lb,mid,hb)
  
}


function sort(arr,lb,mid,hb){
  let b=[];
  let i=lb,j=mid+1;k=0
  while(i<=mid && j<=hb){

    if(arr[i]<=arr[j]){
      b[k]=arr[i];i++;k++
    }
    else {
        b[k]=arr[j];j++;k++
    }
  }

    while(i<=mid){
    b[k]=arr[i];i++;k++;
  }

  while(j<=hb){
    b[k]=arr[j];j++;k++;
  }

 for(q=0,w=lb;q<b.length;q++,w++)
   sorted_arr[w]=b[q]

}

How can I enable Scrolling on a Path element inside an SVG

I have a react component that draws lines connecting different elements. The lines are drawn using svg in the following manner:

     <svg key={index} className='w-9/12 h-[93%]' style={{ position: 'absolute', zIndex: 100, pointerEvents: 'auto' }}>
          <PathLine
            points={
              [
                { x: path.startX, y: path.startY }, 
                { x: path.startDeltaX - index, y: path.startDeltaY }, 
                { x: path.endDeltaX - index, y: path.endDeltaY }, 
                { x: path.endX, y: path.endDeltaY }
              ]
            }
            stroke="red"
            strokeWidth="3"
            fill="none"
            r={10}
          />
        </svg>

Now the issue is, when I place my cursor over the svg element, I am able to scroll on both axis without any issues. However, when I place my cursor on the Path element, which is what is generated by the PathLine scroll events do not work. Its like a black hole on the page where scroll events are either not firing or have been disabled. I have tried to update the pointerEvents on both objects to no avail.

Not really sure what I am doing wrong 😀

ckeditor and mathtype in angular

i have already tried using getElementbyClassName append class

I want to assign the values directly (without clicking the insert button). in ckeditor5 what is typed in math type

What I am expecting means I want to show the values directly based on what I typed in math in Angular.
Anyone has to resolve my problem.

Detecting if the user is on desktop or mobile in the browser

I have a web page and am trying to detect if the user is accessing the page on the desktop or on the mobile. What is the typical way to do this? Note I dont want to use the page width (e.g. window.innerWidth <= 767) to check as the user may simply have resized the desktop. Can someone assist in the best way to achieve this?

Thanks!

Spread operator only returns the first value in Google apps script

I am totally stuck with a problem.

I’m trying to insert some values in a Google sheet using a Google Apps Script, but when I’m spreading the range that I defined earlier, it only returns the first value.

I expected Logger.log(...pasteAndFormatRange);, Logger.log(pasteAndFromatRange.flat(), and Logger.log(pasteAndFormatRange[0], pasteAndFormatRange[1], pasteAndFormatRange[2], pasteAndFormatRange[3]); to return 2.0, 1.0, 626.0, 9.0 , but it only returns 2.0.

I expected Logger.log(pasteAndFormatRange); and Logger.log([...pasteAndFormatRange]); to return [2.0, 1.0, 626.0, 9.0], which it does.

I have made sure that the typeof the array is in fact an object. I have tried making a new array from this array in several ways, but the new array behaves the same way.

Also this worked just fine a week ago… I guess my next step would be to define the range inside the .getRange()-method directly, but then I wouldn’t be able to keep my code DRY 🙁

Here is the code:

let pasteAndFormatRange;

  if (action === 'override') {
    pasteAndFormatRange = [2, 1, target.getLastRow()-1, target.getLastColumn()];
  }

  Logger.log(pasteAndFormatRange); // returns [2.0, 1.0, 626.0, 9.0]
  Logger.log([...pasteAndFormatRange]); // returns [2.0, 1.0, 626.0, 9.0]
  Logger.log(...pasteAndFormatRange); // returns 2.0
  Logger.log(pasteAndFormatRange[0], pasteAndFormatRange[1], pasteAndFormatRange[2], pasteAndFormatRange[3]); // returns 2.0

target.getRange(...pasteAndFormatRange).setValues(data.slice(1));

How do I get my transition hamburger menu line to work in reverse in CSS/JS?

let a = document.getElementsByClassName("mobile1")[0];

document.querySelector(".button-one").addEventListener("click", ()=>{
    a.classList.toggle("mobile2");
})
button{
        background: transparent;
        border:3px #000 solid;
        border-radius: 0.25rem;
        position:absolute;
        left: 20px;
        top:20px
    }
    
    .button-one{
        align-items: center;
        display: flex;
        height: 21px;
        width: 30px;
    }
    
    .mobile1 {
        background-color: black;
        height: 3px;
        width: 100%
    }
    
    
    .mobile1{
        
        background-color: currentColor;
        position:absolute;
        left:0;
        top:12px;
        transition: top 250ms ease, 
                    transform 250ms ease 250ms
                        ;
        transform-origin: center;
        width:100%
    }
    
    .mobile2 {
        top:0;
        width:100%;
    }
    
    .mobile2 {
        transform:rotate(-45deg);
    }
<button class="button-one">
                <div class="mobile1">
                </div>
</button>

I am trying to get my hamburger menu to work but it doesn’t (not as I want to anyway). The animation transition works upon clicking the button first time round, but upon clicking it again it does its own thing.

Here’s some code

CSS

    
    button{
        background: transparent;
        border:3px #000 solid;
        border-radius: 0.25rem;
        position:absolute;
        right: 20px;
        top:20px
    }
    
    .button-one{
        align-items: center;
        display: flex;
        height: 21px;
        width: 30px;
    }
    
    .mobile1 {
        background-color: black;
        height: 3px;
        width: 100%
    }
    
    
    .mobile1{
        
        background-color: currentColor;
        position:absolute;
        left:0;
        top:12px;
        transition: top 250ms ease, 
                    transform 250ms ease 250ms
                        ;
        transform-origin: center;
        width:100%
    }
    
    .mobile2 {
        top:0;
        width:100%;
    }
    
    .mobile2 {
        transform:rotate(-45deg);
    }
    .mobile2{
        transition: transform 250ms ease,
                    top 250ms ease 250ms;
    }
    
    

here’s the Javascript:

let a = document.getElementsByClassName("mobile1")[0];

document.querySelector(".button-one").addEventListener("click", ()=>{
    a.classList.toggle("mobile2");
})

and here’s a snippet of HTML:

<button class="button-one">
   <div class="mobile1">
   </div>
</button>

Any help appreciated…

Installed SwiperJs and having problems Importing pagination from modules

Installed SwiperJs and having problems Importing pagination from modules in my nextjs project. I get the error “Module not found: Package path ./modules is not exported from package”

I tried updating the module to the latest and forced installing package but still didnt get any results.

import { Swiper, SwiperSlide } from "swiper/react";
import { Pagination } from "swiper/modules";


  <Swiper pagination modules={[Pagination]} className="mySwiper">
    {media?.map((media, idx) => (
      <SwiperSlide key={idx}>
        <Image
          className="rounded-lg"
          src={media?.url}
          alt={"variant Media"}
          width={50}
          height={30}
        />
      </SwiperSlide>
    ))}
  </Swiper>

Data manipulation in multidimension arrays

I have an multidimensional array and it contains 5 arrays and each of these 5 arrays contain different number of arrays. For example array at index # 0 contains 99 arrays of same length and array at index # 1 contain 300 arrays of same length. All of these arrays contain combination made from a single array who has 27 elements in it. Now I want to take a single combinations from all five array and get a single multidimensional array of length 5 who has the same number of elements as the original array of 27 elements.

I have tried using for loops but indexing through each of the combination at all 5 places to get an array of 5 arrays whose elements collectively are equal to the original arrays but the amount of iteration are way too much. Is there any better way of doing this.

enter image description here

Issues with Rendering in Express.js: Home, Login, Register Not Displaying

I’m facing an issue with my Express.js application where none of the views (home.ejs, login.ejs, register.ejs) seem to be rendering, and I’m encountering a “This site can’t be reached – The connection was reset” error. As someone new to web development, I’m seeking assistance to identify and resolve the problem.

Here’s my code:

import bodyParser from "body-parser";
import express from "express";
import mongoose from "mongoose";
import bcrypt from "bcrypt";

const app = express(); 
const port = 9000;

app.use(express.static('public'));
app.set('view engine', 'ejs');  
app.use(bodyParser.urlencoded({ extended: true })); 
mongoose.connect("mongodb://localhost:27017/usersdb"); 

const userSchema = new mongoose.Schema({
    username: String,
    password: String
});

const User = mongoose.model('User', userSchema); 

app.get('/', function(req, res) {
    try {
        res.render("home"); 
    } catch (error) {
        console.error(error, 'Home not Rendering');
        res.status(500).send('Internal Server Error');
    }
});

app.get('/register', function(req, res) {
    res.render("register")
});

app.get('/login', function(req, res) {
    res.render("login")
});

app.post('/register', async (req, res) => {
    try {
        const hashedPassword = await bcrypt.hash(req.body.password, 10);
        const newUser = new User({
            username: req.body.username,
            password: hashedPassword
        });
        await newUser.save();
        res.redirect('/login'); // Redirect to login page after successful registration
    } catch (error) {
        console.error(error, 'Error during registration');
        res.status(500).send('Internal Server Error');
    }
});

app.listen(port, () => {
    console.log(`The server is running on http://localhost:${port}`);
});

Template Directory:
Make sure your views directory is in the correct location and contains your EJS files (home.ejs, register.ejs, and login.ejs). By default, Express looks for the views directory in the root of your project.

Image of directory: https://i.stack.imgur.com/khWXf.png

Ensure that the views directory is correctly structured and contains the necessary EJS files.

Template Rendering:
Ensure that the EJS templates are correctly set up and include the necessary HTML/EJS code for rendering. For example, in your home.ejs, register.ejs, and login.ejs files, you should have the appropriate EJS syntax for rendering content.

View Engine Setup:
Double-check your view engine setup. You’ve set the view engine to EJS using app.set(‘view engine’, ‘ejs’);. Make sure that the EJS module is installed (npm install ejs) and listed as a dependency in your package.json file.

Redirects:
In your /register route, you’re saving the user to the database, but there’s no response or redirection. Consider redirecting the user to another page or rendering a success message.

I have a bot in telegram can I delete user’s messages?

I am writing a bot on JS using grammy bibliothek I made a function createStickerPack everything works but I need to make it so that when the user sends sticker pack names after creating a sticker the user’s messages are deleted how to do it ?
I have a sample code how to do it but it doesn’t work, maybe there are people who can help me.

`bot.on('message', async (ctx) => {
  // console.log(ctx.message)
  if (ctx.message && ctx.message.text) {
    const userId = ctx.message.from.id;

    const sentMessage = await ctx.reply('Please wait...');

    setTimeout(async () => {
      try {
        // Delete the user's message
        await ctx.deleteMessage(sentMessage.chat.id, sentMessage.message_id);
        await ctx.deleteMessage(ctx.message.chat.id, ctx.message.message_id); // Delete user message
      } catch (error) {
        console.error('Error while deleting message:', error);
      }
    }, 5000); // Delete message after 5 seconds 2(in the example)
  }
});`
`bot.on('message', async (ctx) => {
  // console.log(ctx.message)
  if (ctx.message && ctx.message.text) {
    const userId = ctx.message.from.id;

    const sentMessage = await ctx.reply('Please wait...');

    setTimeout(async () => {
      try {
        // Delete the user's message
        await ctx.deleteMessage(sentMessage.chat.id, sentMessage.message_id);
        await ctx.deleteMessage(ctx.message.chat.id, ctx.message.message_id); // Delete user message
      } catch (error) {
        console.error('Error while deleting message:', error);
      }
    }, 5000); // Delete message after 5 seconds 2(in the example)
  }
});`

I have a project about firabse authentication, but I get an error while registering

app.post("/signup", async (req, res) => {
    const { name, email, password, confirmPassword } = req.body;
    try {
        const userCredential = await createUserWithEmailAndPassword(auth, email, password);
        const user = userCredential.user;
        const docRef = await addDoc(collection(db, 'userdata'), {
            uid: user.uid,
            name: name,
            email: email,
            premium: 0
        });
        console.log('Added user document with ID: ', docRef.id);
        res.redirect("/login");
    } catch (error) {
        console.error("Signup error:", error);
        res.status(500).json({ error: "Signup error" });
    }
});

I’m getting Signup error: FirebaseError: Firebase: Error (auth/admin-restricted-operation).
at createErrorInternal (C:UsersxexezDesktopsavoryscripter-premiumnode_modules@firebaseauthdistnodetotp-d9065ba0.js:536:55)
at _fail (C:UsersxexezDesktopsavoryscripter-premiumnode_modules@firebaseauthdistnodetotp-d9065ba0.js:507:31)
at C:UsersxexezDesktopsavoryscripter-premiumnode_modules@firebaseauthdistnodetotp-d9065ba0.js:1002:29
at step (C:UsersxexezDesktopsavoryscripter-premiumnode_modulestslibtslib.js:195:27)
at Object.next (C:UsersxexezDesktopsavoryscripter-premiumnode_modulestslibtslib.js:176:57)
at fulfilled (C:UsersxexezDesktopsavoryscripter-premiumnode_modulestslibtslib.js:166:62)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: ‘auth/admin-restricted-operation’,
customData: {}
}
error in my code and I couldn’t solve it no matter what I did. There is no problem with the login process, I just get an error while registering.

I have a code like this

<form class="login100-form validate-form" action="/signup" method="POST">
                    <div class="wrap-input100 validate-input">
                        <input class="input100" type="text" name="name" placeholder="Adınız">
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <i class="fa  fa-address-book" aria-hidden="true"></i>
                        </span>
                    </div>

                    <div class="wrap-input100 validate-input" data-validate="Valid email is required: [email protected]">
                        <input class="input100" type="email" name="email" placeholder="Email">
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <i class="fa fa-envelope" aria-hidden="true"></i>
                        </span>
                    </div>

                    <!-- Update Signup Form (HTML) -->
                    <div class="wrap-input100 validate-input" data-validate="Password is required">
                        <input class="input100" type="password" name="password" id="password" placeholder="Şifre">
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <i class="fa fa-lock" aria-hidden="true"></i>
                        </span>
                    </div>
                    <div class="wrap-input100 validate-input" data-validate="Password is required">
                        <input class="input100" type="password" name="confirmPassword" id="confirmPassword"
                            placeholder="Şifre Tekrar">

                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <i class="fa fa-lock" aria-hidden="true"></i>
                        </span>
                        <div id="passwordMismatch" style="color: red;"></div>
                    </div>
                    <div id="passwordLengthError" style="color: red;"></div>
                    <div id="emailExistsError" style="color: red;"></div>


                    <div class="container-login100-form-btn">
                        <button class="login100-form-btn" type="submit">Kayıt Ol</button>

                    </div>



                    <div class="text-center p-t-136">
                        <a class="txt2" href="login">
                            Giriş Yap
                            <i class="fa fa-long-arrow-right m-l-5" aria-hidden="true"></i>
                        </a>
                    </div>
                </form>

and when you write your username, e-mail, password and password repeat, it should be sent to /login, but it doesn’t work.