3js if statement doesn’t work Putting it outside the if statement works fine

  function hover(event) {
// mouse.x = (event.clientX / window.innerWidth) * 2 - 1
// mouse.y = -(event.clientY /500) * 2 + 1

if(window.innerWidth >=1024){    
  mouse.x = (event.clientX / 1000) * 2 - 1
  console.log('큼'+mouse.x)
}else if( window.innerWidth >=768){
  mouse.x = (event.clientX / window.innerWidth) * 2 - 1
  console.log('중간'+mouse.x)
}else{
  mouse.x = (event.clientX / 400) * 2 - 1
  console.log('작음'+mouse.x)
}


if(window.innerWidth >=1024){    
  mouse.y = (event.clientY / window.innerHeight) * 2 + 1
}else if(window.innerWidth >=768){
  mouse.y = (event.clientY / 500) * 2 + 1
}else{
  mouse.y = (event.clientY / 300) * 2 + 1
}

The if statement should have a different mouse.x(y) operation depending on the browser size, but it does not work.

If you put it outside the if statement, it works one by one.
When I take a picture of the console, it is recognized fine.

Merge two arrays by name value in javascript

var arr1 = [{name: "lang", age: "23"},{name:"shen", "age" : "18"}];
var arr2 = [{name : "shen Fajarda", status: "married"}];

How to merge this 2 arrays by name though the name in arr1 has the name shen while the arr2 has the whole name shen Fajarda.

This the output that i need,

var arr3 = [{name: "lang", age: "23"},{name:"shen", age : "18",status:"married"}];

how to increase the views field in firebase with nextjs [duplicate]

I am trying to get the pageViews for the pages the visitors visit. But for some reason, the code increases only the first time. Can you please help, I am new to firebase and nextjs.

function handleViewsCounter(idRef) {
   const idReference = fire.firestore().collection('blogs').doc(idRef)
     return idReference.update({views: views + 1})
}

every time I click on the function, it should increase the views field in firebase, but that is not what is happening. It only increases one time and that gets sent to the firebase once.

reduxjs toolkit – always give error “Unexpected token u in JSON at position 0” on rejected condition

i already take few hourse to solve this, but still not done yet. can somebody help me to solve this pls.

import { createSlice, createAsyncThunk, current } from ‘@reduxjs/toolkit’;
import axios from ‘axios’;

export const addToCart = createAsyncThunk(
  'cart/addCart',
  async (obj, thunkAPI) => {
    const response = await axios.get(
      `http://localhost:8000/api/products/${obj.id}`
    );
    const data = await response.data;
    thunkAPI.dispatch(
      cartAdd({
        product: data._id,
        name: data.name,
        image: data.image,
        price: data.price,
        countInStock: data.countInStock,
        qty: obj.qty,
      })
    );
    localStorage.setItem(
      'cartItems',
      JSON.stringify(thunkAPI.getState().cart.cartItems)
    );
  }
);

const cartItemsFromStorage = localStorage.getItem('cartItems')
  ? JSON.parse(localStorage.getItem('cartItems'))
  : [];

const cartSlice = createSlice({
  name: 'cart',
  initialState: {
    isLoading: false,
    cartItems: cartItemsFromStorage,
  },
  reducers: {
    cartAdd(state, { payload }) {
      const existItem = JSON.parse(JSON.stringify(state.cartItems)).find(
        (elem) => elem.product === payload.product
      );

      console.log(existItem);
      if (existItem) {
        return {
          ...state,
          cartItems: state.cartItems.map((x) =>
            x.product === payload.product ? payload : x
          ),
        };
      } else {
        return {
          ...state,
          cartItems: [...state.cartItems, payload],
        };
      }
    },
  },
  extraReducers: {
    [addToCart.pending]: (state, { payload }) => {
      state.isLoading = true;
    },
    [addToCart.fulfilled]: (state, action) => {
      state.isLoading = false;
      state.cartItems = action.payload;
    },
    [addToCart.rejected]: (state, action) => {
      console.log(action);
      state.isLoading = false;
    },
  },
});

the existing item give the result

{product: '628f92cfab7a84a5ab78fa3a', name: 'Airpods Wireless Bluetooth Headphones', image: '/images/airpods.jpg', price: 89.99, countInStock: 10, …}
countInStock: 10
image: "/images/airpods.jpg"
name: "Airpods Wireless Bluetooth Headphones"
price: 89.99
product: "628f92cfab7a84a5ab78fa3a"
qty: 1
[[Prototype]]: Object

but rejected condition always give this

"SyntaxError: Unexpected token u in JSON at position 0
    at JSON.parse (<anonymous>)
    at cartAdd (http://localhost:3000/static/js/bundle.js:932:30)
    at http://localhost:3000/static/js/bundle.js:3172:20
    at produce (http://localhost:3000/static/js/bundle.js:69721:15)
    at http://localhost:3000/static/js/bundle.js:3171:67
    at Array.reduce (<anonymous>)
    at reducer (http://localhost:3000/static/js/bundle.js:3147:25)
    at reducer (http://localhost:3000/static/js/bundle.js:3241:14)
    at combination (http://localhost:3000/static/js/bundle.js:63408:29)
    at k (<anonymous>:2235:16)"

can somebody help to get through this? thank you very much

error: while ln logout route using passport local mongoose [closed]

Error: req#logout requires a callback function
    at IncomingMessage.req.logout.req.logOut (C:UsersHpDesktopProjectSecretsnode_modulespassportlibhttprequest.js:65:44)
    at C:UsersHpDesktopProjectSecretsapp.js:72:7
    at Layer.handle [as handle_request] (C:UsersHpDesktopProjectSecretsnode_modulesexpresslibrouterlayer.js:95:5)
    at next (C:UsersHpDesktopProjectSecretsnode_modulesexpresslibrouterroute.js:144:13)
    at Route.dispatch (C:UsersHpDesktopProjectSecretsnode_modulesexpresslibrouterroute.js:114:3)
    at Layer.handle [as handle_request] (C:UsersHpDesktopProjectSecretsnode_modulesexpresslibrouterlayer.js:95:5)
    at C:UsersHpDesktopProjectSecretsnode_modulesexpresslibrouterindex.js:284:15
    at Function.process_params (C:UsersHpDesktopProjectSecretsnode_modulesexpresslibrouterindex.js:346:12)    
    at next (C:UsersHpDesktopProjectSecretsnode_modulesexpresslibrouterindex.js:280:10)
    at SessionStrategy.strategy.pass (C:UsersHpDesktopProjectSecretsnode_modulespassportlibmiddlewareauthenticate.js:346:9)

can I return a alert?

I’m learning Arrow functions basics, and have some questions, hoping somebody might give me a clue.

I learned it from this website. https://javascript.info/arrow-functions-basics

1.
they say => means return its results, and they wrote something like this:

let sayHi = () => alert("Hello!");
sayHi();

which make me a bit confused, can I return an alert? becasue I have only seen this(below) before:

funtion showOk(){
alert('you agreed')
}

there’s no return written before alert. they just alert something and didn’t return it. so if I want to write sayHi() in a different way, would it be like this(below)?that’s the correct answer?

let sayHi = function() {
return alert("Hello!");
};
sayHi();

2.
another question is arguments.

let func = (arg1, arg2, ..., argN) => expression;

They say “This creates a function func that accepts arguments arg1..argN, …”, and then they give you another concrete example:

let sum = (a, b) => a + b;

/* This arrow function is a shorter form of:

let sum = function(a, b) {
  return a + b;
};
*/

alert( sum(1, 2) ); // 3

here’s the question, I thought a and b are parameters, not arguments, the arguments in this code should be 1 and 2?
so what should I write in ()?

thank you for reading my questiones.

Can someone please explain why my javascript function does not work, and how to improve?

these are my starter variables.

var gameData = {
    Points: 0,
    PointsPerClick: 1,
    PointsPerClickCost: 10
  }

I am just trying to say that once I have ten or more points- then something happens. I have tried various functions, but the IDE seems to ignore them all. This is just an example. Am I doing something wrong?

function LevelTen() {
if (gameData.Points >= 10) {
  alert("This is an alert message box.");  // display string message
}

My end goal is to add an image that pops up once a user gets to level ten. The above is just an example. Thank you for any tips! I am stumped and have been trying to get the functions to work for hours. Anytime I set the variables to an integer, the code seems to get ignored. The rest of my code runs great.

Particles don’t show up on my web page using tsparticles

I’m trying to use tsparticles, and I followed the following steps:
I first installed the package using npm install react-tsparticles.
Then I created a component including two files, the particles component:

import React from 'react';
import Particles from 'react-tsparticles';
import ParticlesOptions from './ParticlesOptions';

const ParticlesBackground = () => {
    return (
        <div>
            <Particles params={ParticlesOptions}>
            </Particles>
        </div>
    )
}

export default ParticlesBackground;

And the particles options:

const ParticlesOptions = {
  fps_limit: 60,
  interactivity: {
    detectsOn: "canvas",
    events: {
      onClick: {
        enable: true,
        mode: "push"
      },
      onHover: {
        enable: true,
        mode: "repulse"
      },
      resize: true
    },
    modes: {
      push: {
        particles_nb: 4
      },
      repulse: {
        distance: 200,
        duration: 0.4
      }
    }
  },
  particles: {
    color: {
      value: "#ffffff"
    },
    links: {
      color: "#ffffff",
      distance: 150,
      enable: true,
      opacity: 0.4,
      width: 1
    },
    move: {
      bounce: false,
      direction: "none",
      enable: true,
      outMode: "out",
      random: false,
      speed: 2,
      straight: false
    },
    number: {
      density: {
        enable: true,
        area: 800
      },
      value: 80
    },
    opacity: {
      value: 0.5
    },
    shape: {
      type: "circle"
    },
    size: {
      random: true,
      value: 5
    }
  },
  detectRetina: true
}

export default ParticlesOptions

I imported the component into my App.js properly as I see no errors, but I still see no particles on my website. Again as I mentioned, no errors are displayed! Here’s my App.js:

import React, {Component} from 'react';
import ParticlesBackground from './components/particles/ParticlesBackground';
import Clarifai from 'clarifai';
import Navigation from './components/navigation/Navigation';
import Logo from './components/logo/Logo';
import ImageLinkForm from './components/imageLinkForm/ImageLinkForm';
import Rank from './components/rank//Rank';
import './App.css';

class App extends Component {
   render() {
    return (
    <div className="App">
      <ParticlesBackground />
      <Navigation />
      <Rank />
      <Logo />
      <ImageLinkForm />
    </div>
    );
  }
}

export default App;

The whole App is displayed properly, and my background isn’t white as I found people who have the same problem and turns out that because of the background color they just couldn’t see the particles.
I fixed my vulnerabilities and reinstalled my packages properly, but it’s still not working!
I also tried to use react-particles-js package instead, but it gives me ‘module not found’ errors.
Any other suggestions? Hope u could help!

Javascript plugins for kotlin applications

I’m currently working on an application that targets the desktop written in Kotlin. Our application is intended to integrate with another application that is essentially driven solely by open-source plugins.

We want our platform to be enticing to these developers and they are currently using JS (it’s an electron application). Our goal is for our desktop, JVM application, to support plugins to be written in Javascript, HTML, and CSS. These will be plugins that operate on top of our application.

I’m curious if there are any libraries, examples using this strategy, or best practices and feasibility to assign what I’m imaging to be a browser window to house the application. This would allow for these languages to be use and also isolate the plugin from the rest of the application.

I appreciate any advice.

Is there a way to change how the hover effect works between mobile browsers? [closed]

https://remarkable-unicorn-e5d5f8.netlify.app/index.html

Above is a link to my project in question. All hover functions work as expected on a computer. The hover functions work with a single tap on mobile when opened with google chrome. But when I viewed the page with safari, the interface was very slow and you have to hold down to activate the hover effect. Is there a way to change that and make the safari interaction more like google chrome? My goal would be for the hover effect to be activated with a single tap instead of having to hold down on the screen, just like chrome browser.

Also, the images on the ‘work’ page were not resized and are large images. Would that be effecting the hover effect or efficiency on safari?

CSS below

.items {
   display: grid;
   grid-template-columns: repeat(3, 1fr);
   box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.3);
}

.item {
   position: relative;
   background: $main-color;
   overflow: hidden;
   
   &::after {
      content: '';
      position: absolute;
      display: block;
      background: inherit;
      opacity: 0.9;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      transform: scale(2) translateX(-75%) translateY(-75%) rotate(-28deg);
      transition: transform 3s cubic-bezier(0.2, 1, 0.3, 1);
   }

   // Bring in main color overlay
   &:hover:after {
      transform: scale(2) translateX(0) translateY(0) rotate(-28deg);
   }

   // Scale image on hover
   &:hover &-image {
      transform: scale(1.2);
   }

   // Bring in text on hover
&:hover &-text {
   opacity: 1;
   transform: translateY(0);
}

&-image {
   height: auto;
   transform: translateZ(0);
   display: block;
   transition: transform 750ms cubic-bezier(0.2, 1, 0.3, 1);
}

&-image::before {
   content: '';
   display: block;
   padding-top: 75%;
   overflow: hidden;
}

&-image img {
   position: absolute;
   top: 0;
   left: 0;
   width: 100%;
   height: auto;
   line-height: 0;
}

&-text {
   position: absolute;
   top: 0;
   left: 0;
   bottom: 0;
   right: 0;
   opacity: 0;
   text-align: center;
   z-index: 1;
   color: #fff;
   transform: translateY(-20%);
   transition: opacity 500ms cubic-bezier(0.2, 1, 0.3, 1), transform 500ms cubic-bezier(0.2, 1, 0.3, 1);
   transition-delay: 300ms;
}

&-text-wrap {
   position: absolute;
   width: 100%;
top: 50%;
transform: translateY(-50%);
}

&-text-title {
   font-size: 2rem;
   padding: 0 1rem;
   margin: 5px 0 0 0;
}

&-text-category {
   text-transform: uppercse;
   font-size: 1.2rem;
   opacity: 0.7;
   margin: 0;
}
}

<section id="work-a" class="text-center py-3">
   <div class="container">
      <h2 class="section-title">My Work</h2>
      <div class="bottom-line"></div>
      <p class="lead">
         Check out some of my projects...
      </p>
      <div class="items">
         <div class="item">
            <div class="item-image">
               <img src="/img/items/item1.png" alt="">
            </div>
            <div class="item-text">
               <div class="item-text-wrap">
                  <p class="item-text-category">Design</p>
                  <h2 class="item-text-title">Great Gradients</h2>
               </div>
            </div>
         </div>
         <div class="item">
            <div class="item-image">
               <img src="/img/items/item2.png" alt="">
            </div>
            <div class="item-text">
               <div class="item-text-wrap">
                  <p class="item-text-category">UI/UX</p>
                  <h2 class="item-text-title">World Experience</h2>
               </div>
            </div>
         </div>
         <div class="item">
            <div class="item-image">
               <img src="/img/items/item3.png" alt="">
            </div>
            <div class="item-text">
               <div class="item-text-wrap">
                  <p class="item-text-category">Photography & Design</p>
                  <h2 class="item-text-title">Vanishing</h2>
               </div>
            </div>
         </div>
         <div class="item">
            <div class="item-image">
               <img src="/img/items/item4.png" alt="">
            </div>
            <div class="item-text">
               <div class="item-text-wrap">
                  <p class="item-text-category">Design</p>
                  <h2 class="item-text-title">Gap INC</h2>
               </div>
            </div>
         </div>
         <div class="item">
            <div class="item-image">
               <img src="/img/items/item5.png" alt="">
            </div>
            <div class="item-text">
               <div class="item-text-wrap">
                  <p class="item-text-category">Mobile UI Design</p>
                  <h2 class="item-text-title">Face The Experience</h2>
               </div>
            </div>
         </div>
         <div class="item">
            <div class="item-image">
               <img src="/img/items/item6.png" alt="">
            </div>
            <div class="item-text">
               <div class="item-text-wrap">
                  <p class="item-text-category">Design Concept</p>
                  <h2 class="item-text-title">Bezier Curves</h2>
               </div>
            </div>
         </div>
         <div class="item">
            <div class="item-image">
               <img src="/img/items/item7.png" alt="">
            </div>
            <div class="item-text">
               <div class="item-text-wrap">
                  <p class="item-text-category">Photography</p>
                  <h2 class="item-text-title">Dock Ponder</h2>
               </div>
            </div>
         </div>
         <div class="item">
            <div class="item-image">
               <img src="/img/items/item8.png" alt="">
            </div>
            <div class="item-text">
               <div class="item-text-wrap">
                  <p class="item-text-category">Web Applications</p>
                  <h2 class="item-text-title">Restaurant App</h2>
               </div>
            </div>
         </div>
         <div class="item">
            <div class="item-image">
               <img src="/img/items/item9.png" alt="">
            </div>
            <div class="item-text">
               <div class="item-text-wrap">
                  <p class="item-text-category">Social Network Concept</p>
                  <h2 class="item-text-title">FriendFeed
               </div>
            </div>
         </div>
      </div>
   </div>
</section>

Could you please provide me the comple solution(logic and code))

Task Summary :Task is to provide product search functionality on the set of content fragments. Content fragment stores the product data with fields like Product Name, Product Created By, Product Description and Product Image.

Task Design Details : One Simple Search form to be created using AEM Form core components with one text field for search text, one drop down field which support two dropdown values , one for product name field and other for product created by field. The search form will invoke a servlet which will search the data using a query from the set of content fragments and as per the user search text input and selected dropdown value. Please extend the Adobe core component / model wherever required to customize the functionality to invoke a servlet. Servlet shall return a JSON response which will contain product description and product image path from DAM.The product description and image from JSON response shall be shown as a result on the same page. Also write down JUNIT class for the servlet with at least 70% coverage. Please create the sample search page using the editable templates. Please configure at least 4 different test product content fragments.

Bar chart JS Math compute zero display nothing

How could we rewrite a minor bit of the JS Math to compute a chart bar row that has nothing [0] and show a result of no color on the bar chart.
The 55, 510a, 510d, 511d have 0 items, so we want the math to compute and result in no color on that horizontal bar. If you look close there is a tiny tiny bit of color still showing at the far left edge.
By nothing we need that bar to be empty, none, blank, null etc.

var horizontal = [
  ["54", 20],
  ["55", null ], //** null data point
  ["56", 20],
  ["57", 40],
  ["58", 100],
  ["59", 20],
  ["510a", -0],
  ["510b", 40],
  ["510c", 20],
  ["510d", -1],
  ["511a", 40],
  ["511b", 20],
  ["511c", 20],
  ["511d", 0],
  ["512a", 80],
  ["512b", 80],
  ["512c", 20],
  ["512d", 40]
];

/*-- Random Color Generator - light color spectrum --*/
// SOURCE: https://gist.github.com/Chak10/dc24c61c9bf2f651cb6d290eeef864c1
function generateLightColorHex() {
  let color = "#";
  for (let i = 0; i < 3; i++)
    color += ("0" + Math.floor(((1 + Math.random()) * Math.pow(16, 2)) / 2).toString(16)).slice(-2);
  return color;
}

/*-- Animation --*/
function animate () {
  var bars = document.getElementById("bar-horzontal").getElementsByTagName("div");
  var i = 0;
  for (var bar of bars) {
    bar.style.width = horizontal[i][1] + "%";
    i++;
  }
}

/*-- Draw the bars on page load --*/
window.addEventListener("load", function(){
  // Draw the horizontal bars
  var container = document.getElementById("bar-horzontal");
  for (var hor of horizontal) {
    var bar = document.createElement("div");
    bar.innerHTML = hor[0];
    bar.style = "background: " + generateLightColorHex() + "; width: 0;";
    container.appendChild(bar);
  }

    // Animate the bars
  setTimeout(animate, 75);
});
/*-- horizontal bar chart --*/
#bar-horzontal {
  max-width: 500px;
  border: 1px solid #000;
  background: repeating-linear-gradient(
    to right,
    #111,
    #efe 2px,
    #efe 20%);
}
#bar-horzontal div {
  color: #000;
  font-weight: 600;
  padding: 5px;
  box-sizing: border-box;
  transition: width 0.5s;
}
<h6>5 bar chart</h6>
<div id="bar-horzontal"></div>

Here is a live test.
https://codepen.io/crux1/pen/KKQZMzN
Source:
https://codepen.io/ontox/pen/NVmKWL