trying to use the fetch API Response object in javascript: https://developer.mozilla.org/en-US/docs/Web/API/Response
I want to return a 500. What’s the API syntax to do so using typescript/javascript?
Blancer.com Tutorials and projects
Freelance Projects, Design and Programming Tutorials
Category Added in a WPeMatico Campaign
trying to use the fetch API Response object in javascript: https://developer.mozilla.org/en-US/docs/Web/API/Response
I want to return a 500. What’s the API syntax to do so using typescript/javascript?
I tried using gsap pin section feature and ScrollTrigger to go next slide.
<div style="--swiper-navigation-color: #fff; --swiper-pagination-color: #fff" class="swiper mySwiper2">
<div class="swiper-wrapper">
<div class="swiper-slide">
<img src="https://swiperjs.com/demos/images/nature-1.jpg" />
</div>
....
</div>
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
</div>
<div thumbsSlider="" class="swiper mySwiper">
<div class="swiper-wrapper">
<div class="swiper-slide">
<img src="https://swiperjs.com/demos/images/nature-1.jpg" />
</div>
....
</div>
</div>
<script>
var swiper = new Swiper(".mySwiper", {
spaceBetween: 10,
slidesPerView: 4,
freeMode: true,
watchSlidesProgress: true,
});
var swiper2 = new Swiper(".mySwiper2", {
spaceBetween: 10,
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
thumbs: {
swiper: swiper,
},
});
const swiper = gsap.to('.mySwiper2', {
yPercent: -100 * (document.querySelectorAll('.mySwiper2.swiper-slide').length - 1),
ease: 'none',
scrollTrigger: {
trigger: '.swiper-container',
pin: true,
scrub: 0.5,
end: '+=100%',
markers: true // Optional: Add markers for visualization
}
});
</script>
I tired going though both documentation and gsap not working. I want to be able pin the swiper section till the last slide. than continue normal scroll.
Please help me add the html div tag in the script
const button = this.createElement("div");
button.classList.add("start_button");
let border = 0;
if (typeof this.config.backgroundImg === "string") {
button.classList.add("button");
border = 1;
}
button.innerText = (typeof this.config.startBtnName === 'string')
? this.config.startBtnName
: this.local("test");
this.config.startBtnName is a text, i need this text to be inside <div>
I tried this '<div>'+this.config.startBtnName+'</div>', but then the div is output as plain text, not an html tag.
Cards getting flip upside down, but I want just two cards to get flipped out of three cards.How can I do that? Also the shuffle function not working.Please kindly guide.Both code I am attaching below.
index.html File Code :-
<div id="shuffle">
<!--- Card 1 -->
<section class="cards">
<div class="cards__single">
<div class="cards__front">
<img src="img/back.jpg" alt="card1"/>
</div>
<div class="cards__back">
<img src="cards/theMoon.jpg" alt="card1"/>
</div>
</div>
<!--- Card 2 -->
<div class="cards__single">
<div class="cards__front">
<img src="img/back.jpg" alt="card1"/>
</div>
<div class="cards__back">
<img src="cards/theChariot.jpg" alt="card1"/>
</div>
</div>
<!--- Card 3 -->
<div class="cards__single">
<div class="cards__front">
<img src="img/back.jpg" alt="card1"/>
</div>
<div class="cards__back">
<img src="cards/theSun.jpg" alt="card1"/>
</div>
</div>
</section>
<br>
<button>Shuffle</button>
</div>
<script src="script/main.js"></script>
main.js File Code:-
//Shuffle Cards
function shuffle(elems) {
allElems = (function(){
var ret = [], l = elems.length;
while (l--) { ret[ret.length] = elems[l]; }
return ret;
})();
var shuffled = (function(){
var l = allElems.length, ret = [];
while (l--) {
var random = Math.floor(Math.random() * allElems.length),
randEl = allElems[random].cloneNode(true);
allElems.splice(random, 1);
ret[ret.length] = randEl;
}
return ret;
})(), l = elems.length;
while (l--) {
elems[l].parentNode.insertBefore(shuffled[l], elems[l].nextSibling);
elems[l].parentNode.removeChild(elems[l]);
}
}
var button = document.querySelector(‘button’);
button.addEventListener(‘click’, function() { shuffle( document.querySelectorAll(‘#shuffle > div’) ) }, false);
//Flip only two amongst three cards
const cards = document.querySelectorAll(“.cards__single”);
function flipCard() {
this.classList.toggle(“flip”);
}
cards.forEach((card) => card.addEventListener(“click”, flipCard));
function showResult(cards) {
var flipCard = [];
for (var i = 0; i < 2; i++) {
flipCard.push(cards[Math.floor(Math.random() * cards.length)]);
}
for (var i = 0; i < flipCard.length; i++) {
flipCard(flipCard[i]);
}
return flipCard;
}
console.log(flipCard);
I have a nextjs application and it’s now using google-login for authentication.
I have a separate backend(nestJS). There is an auth api which accepts the id token sent from frontend after google login. After verifying user on backend, it will generate a jwt token, and then return the jwt token as part of the api response.
await axios.post(
"http://127.0.0.1:3001/auth/google-login",
{
token: props.account?.id_token,
}
);
Now I am trying to integrate next-auth for controlling the session flow. However, when I am setting up, I don’t know where should I send the /auth request to the backend, and How to store the jwt token received for next-auth.
How should I handle it in this case?
/app/api/auth/[…nextauth]/route.ts
import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import axios from "axios";
const handler = NextAuth({
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID ?? "",
clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? "",
}),
],
callbacks: {
async signIn(props) {
try{
// Tried to do it here but received error - AxiosError: connect ECONNREFUSED 127.0.0.1:3001
const loginRes = await axios.post(
"http://127.0.0.1:3001/auth/google-login",
{
token: props.account?.id_token,
}
);
console.log(loginRes);
}catch(err) {
console.log({err})
}
return true;
},
async redirect({ baseUrl }) {
return baseUrl;
},
async session({ session, user, token }) {
return session;
},
async jwt({ token, user, account, profile, isNewUser }) {
return token;
},
},
});
export { handler as GET, handler as POST };
unctions can be deployed with firebase deploy.
? What should be the name of this codebase? hmxcallkit
? In what sub-directory would you like to initialize your functions for codebase hmxcallkit? firebase.json
? What language would you like to use to write Cloud Functions? JavaScript
? Do you want to use ESLint to catch probable bugs and enforce style? No
Error: An unexpected error has occurred.
why it is showing error
i tried to check my project directory path , i had run firebase login , retried the command , tried with ESlint and without ESlint .
Is there any idea on how to trigger / detect a changement on a javascript variable ?
the mail goal is to show on every change , the new value of the variable in a span .
I searched on the internet but I found that there is no event or Eventlistner that works with variable
I made this basic e-commerce web app using next js ( using nextjs 14 ) and i wanted to deploy it with github pages i followed a tutorial on youtube and i tried deploying by using gh-page branch and github actions and both end up showing only the readme when you visit the website.I did change the branch from the main to gh-pages at the source and still the same .Can anyone help me ?
[github pages link –]
[1]: https://noelkasemi.github.io/strength-palace/
[My github repo –]
[1]: https://github.com/noelkasemi/strength-palace
In web we have PerformanceLongTaskTiming API which represents job units that occupy the UI thread.
And we have TBT metric, which measures how long browser had been blocked during page load. But we measure it only until a first quite window. And it does not cover entire page lifetime. Yes, there is new INP metric, which measure paint after interactions, but not background job.
My question is which formula for long tasks f(...long_tasks) we could use to measure web page blocking during entire page life?
There is Event Loop Lag, for example, but it was design for long running server-side applications, not for typical web pages surfing.
Is it possible to set a 3D plane as a skybox in threejs? If so, how does that work?
I tried looking at Youtube videos and googling, but every tutorial uses an img instead. Would I just have to screenshoot it and just use that for the skybox?
I’m facing this error…
I’m trying to use storybook for the first time and when trying to document a component this error appears, the funny thing is that my react application is working normally.
This component StyledLink.js is inside the component called Menu, and Menu is inside NavBar that I am importing directly into the App file
// File StyledLink.js
import styled from 'styled-components';
import { Link } from 'react-router-dom';
const StyledLink = styled(Link)`
color: #222;
text-decoration: none;
font-size: clamp(3rem, 4vw, 6vw);
font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
transition: 0.2s all ease-in-out;
user-select: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
&:hover {
transition: 0.2s all ease-in-out;
color: orangered;
}
`;
export default StyledLink;
// file StyledLink.stories.js
import StyledLink from './StyledLink';
export default {
title: 'Layouts/NavBar/Menu/StyledComponents/StyledLink',
component: StyledLink,
};
export const Default = {};
\ App.jsx
import React from 'react';
import { Home, Page404 } from './Views';
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import { NavBar } from './Layouts';
const App = () => {
return (
<BrowserRouter>
<NavBar />
<Routes>
<Route path="/" element={<Home />} />
<Route path="/page-not-found" element={<Page404 />} />
</Routes>
</BrowserRouter>
);
};
export default App;
I saw some answers that could be the lack of BrowserRouter but as you can see I’m wrapping the NavBar component with it
I haven’t been able to find a nice way to do this. Here’s what I tried:
allowJs and checkJs are both true in tsconfig.json, then include the files of your project, for the most part.When writing files inside the project (which we wish to publish as a library on NPM), type checking works great: one JS file (with JSDoc comments for type annotations) can be imported into any other JS file. All is great.
Now, the trouble comes with publishing this project, and getting the types to be visible in a downstream dependency. For example, making the types be visible in an app that installs the published project as a package with npm install the-package.
Ok, with the project working well locally, now we try to publish. Here are some methods I’ve tried, taking into account that all my source code is in the project’s src/ folder:
Don’t output anything:
types to src/index.js
Output declarations only:
output declarations in separate folder
emitDeclarationOnly to trueoutDir to (for example) dist.disttypes in package.json to dist/index.d.ts (for example when src/index.js is the package entry point that exports everything from the package)the-package, for example `import {whatever} from ‘the-package’import {something} from 'the-package/src/something.js'. TypeScript will not be able to fine the types for this file (however VS Code will happoly run Go To Definition and take you to something, and the JSDoc-commented types will be there, but apparently TypeScript likes to ignore them)output declarations as sibling files to the source files
emitDeclarationOnly to trueoutDir to src to make the declarations appear in next to all the .js filesOutput both declaration files and .js files
dist/
dist/, and JS files in src/, duplicating the lib. The desired purpose of writing JS + JSDoc is to have a single source of JS files that simply works (regardless if there are type definitions for TS users).All of these options are a no-go for various reasions (f.e. duplicate source, type definitions not visible when importing sub-paths, or TS simply ignoring types that actually exist).
How can it be achieved with minimal effort?
One way I thought of, which is not as minimal as I’d like, is to always delete the .d.ts files and run the TypeScript compiler from scratch every time, on file changes. Obviously this has more overhead and slowdown, but it would work. This method would also break many things (for example TypeScript server, or other build tools depending on TS types like ESLint with TS plugins in watch mode) will inevitably break due to source files completely disappearing and reappearing. It will be a bad developer experience with any tooling in place other than the build itself.
I have a basic vue/vite app that contains:
Header
Footer
Can I give the RouterView a class so that every view has the same class?
import React, {
useState,
useEffect
} from 'react';
export default function App() {
// State to hold the array of results
const [joke, setJoke] = useState([]);
useEffect(() => {
fetch("https://opentdb.com/api.php?amount=10")
.then(res => res.json())
.then(data => setJoke(data.results))
.catch(error => console.error(error));
}, []);
// Map over the results and create JSX elements
const jokeElements = joke.map((item, index) => (<h2 key={index}>{item.question}</h2>));
return (<div>{jokeElements}</div>);
}
It is giving me an issue of
Cannot read properties of undefined (reading ‘map’)
How can I fix that it won’t show this issue anymore?
I have a lottery simulator program, and the math is all turning out completely wrong
var min = 1
var max = 106
function getint(min, max) {
return Math.floor(Math.random() * (max - min) ) + min;
}
alert("Welcome to lottery simulator!")
var money = 10
alert("your goal is to make it to ten thousand dollars")
for (i = 1; i <= 999999999999; i++) {
if (money === 10000) {break;}
if (money > 10000) {break;}
if (money === 0) {break;}
alert("you have " + money + " dollars")
var amount = prompt("how much money would you like to risk?")
if (amount === "dev") {money = 10000}
if (amount === "dev2") {money = 9999999}
if (amount > money) {alert("you do not have that much money")} else if (amount < 0) {alert("you cannot risk negative money")} else if (amount === "end") {throw new error("game ended")} else {
getint()
var outcome = Math.floor(Math.random() * (max - min) ) + min
if (outcome < 50){alert ("you won nothing"); money = money - amount}
if (outcome >= 50 && outcome <= 70) {money = money - amount / 2; alert("you lost 50 percent")} else if (outcome >= 70 && outcome <= 80) {alert("you got your money back")} else if (outcome >= 80 && outcome <= 85) {alert("you got 1.5 times your money"); {money = money + amount + amount / 2} } else if (outcome >= 90 && outcome <= 95) {alert("you doubled your money"); money = money + amount * 2} else if (outcome >= 95 && outcome <= 100) {alert("you tripled your money"); money = money + amount * 3} else if (outcome >= 100 && outcome >= 105) {alert("you got 10 times your money"); money = money + amount * 10} else if (outcome === 106) {alert("jackpot!!!"); money = money + 999999999999999999999999999999}
}
}
if (money === 0) {alert ("you ran out of money and lost")} else if (money === 10000) {alert ("you won!")} else if (money > 10000) {alert("you won!")}
i am not sure but is js math not completely math maybe?