RTK Query Error handling/ _a2 is undefined?

I’ have many different RTK Query calls made throughout my app, and they all have been working fine (get, post, patch, delete). Yet on my current component with a post call, I’m getting an error that I have not seen before and cannot figure out what is tripping it up. The error I’m getting is name: “TypeError”, message: “_a2 is undefined”, followed by a long stack starting with fetchBaseQuery. The call to the backend works fine on Postman, I have no props or fields defined as _a2 (or anything close to that), the stack trace has no reference to an _a2, and I cannot find anything online referencing the same error. Is this something that anyone has seen?

I tried getting more detail from the error based on the suggestions from the docs, but these all return undefined. So maybe not an RTK Query error? If not though, I’m at a total loss.
https://redux-toolkit.js.org/rtk-query/usage/error-handling

I have my set up below, in case I’m just completely overlooking a simple syntax issue.

apiSlice call:

addGoal: builder.mutation({
            query: (arg) => {
                const {planId, values} = arg;
                return {
                url: `/planapi/goals/${planId}`,
                method: 'POST',
                body: values
                }, console.log(values)
            },
            invalidatesTags: ['Goals']
        }),

the component making the call:

const AddGoal = ({planId}) => {
  
  const [addNewGoal, { error }] = useAddGoalMutation()
    
  let rtkerror
  if (error) {
        console.log("error", error.status, error.data) //returns undefined
        rtkerror = <div><h3>{error.status} {JSON.stringify(error.data)}</h3></div>
       //nothing is rendered from this, probably because coming back undefined?
    }


  const [open, setOpen] = React.useState(false);
  console.log("planId ", planId)


  const handleClickOpen = () => {
    setOpen(true);
  };

  const handleClose = () => {
    setOpen(false);
  };
   
  return (
  <div>
    <Button variant="contained" onClick={handleClickOpen}>
      Add Goal
    </Button>
    <Dialog open={open} onClose={handleClose}>
      <DialogTitle>Add New Goal {rtkerror} </DialogTitle>
      <DialogContent>
       
  
  <Formik
    initialValues={{
      title: '',
      dataCollection: '',
      staffRole: '',
      frequency: '',
      location: '',
      projectedHours: '',
      materials: '',
      currentStatus: '',
      quote: '',
      measurement: '',
      plan: ''
    }}
    validationSchema={validationSchema}
  
    onSubmit={async (values) => {

      console.log(values);
      
      try {
      const payload =  await addNewGoal({ planId, values })
      .unwrap()
      .then((payload) => console.log('fulfilled', payload)) //this is also logging fulfilled undefined
      .catch((error) => console.error('rejected', error)); //I've tried as error.status and error.data but these return undefined.
        console.log('fulfilled', payload)
      } catch (err) {
        console.error('Failed to save goal: ', err)
        toast.error("Error Adding Goal", {
          position: toast.POSITION.TOP_CENTER
        });
      }

      toast.success("Goal Added", {
        position: toast.POSITION.TOP_RIGHT
      });
      //handleClose();
      
    }}>
  
 
    {formik => (
      <form onSubmit={formik.handleSubmit}>
        <TextField
          id="title"
          name="title"
          label="Title/ Name of Goal"
          placeholder=''
          value={formik.values.title}
          onChange={formik.handleChange}
          error={formik.touched.title && Boolean(formik.errors.title)}
          helperText={formik.touched.title && formik.errors.title}
        />
        <TextField         
          id="dataCollection"
          name="dataCollection"
          label="Data Collection"
          placeholder=''
          value={formik.values.dataCollection}
          onChange={formik.handleChange}
          error={formik.touched.dataCollection && Boolean(formik.errors.dataCollection)}
          helperText={formik.touched.dataCollection && formik.errors.dataCollection}
        />
        <TextField
          id="staffRole"
          name="staffRole"
          label="Staff Role"
          placeholder=""
          value={formik.values.staffRole}
          onChange={formik.handleChange}
          error={formik.touched.staffRole && Boolean(formik.errors.staffRole)}
          helperText={formik.touched.staffRole && formik.errors.staffRole}
        />
        <TextField         
          id="frequency"
          name="frequency"
          label="Times/Month"
          placeholder=""
          value={formik.values.frequency}
          onChange={formik.handleChange}
          error={formik.touched.frequency && Boolean(formik.errors.frequency)}
          helperText={formik.touched.frequency && formik.errors.frequency}
        />
        <TextField         
          id="location"
          name="location"
          label="Location"
          placeholder=""
          value={formik.values.location}
          onChange={formik.handleChange}
          error={formik.touched.location && Boolean(formik.errors.location)}
          helperText={formik.touched.location && formik.errors.location}
        />
        <TextField         
          id="projectedHours"
          name="projectedHours"
          label="Projected Hours"
          placeholder=""
          value={formik.values.projectedHours}
          onChange={formik.handleChange}
          error={formik.touched.projectedHours && Boolean(formik.errors.projectedHours)}
          helperText={formik.touched.projectedHours && formik.errors.projectedHours}
        />
        <TextField         
          id="materials"
          name="materials"
          label="Materials Used"
          placeholder=""
          value={formik.values.materials}
          onChange={formik.handleChange}
          error={formik.touched.materials && Boolean(formik.errors.materials)}
          helperText={formik.touched.materials && formik.errors.materials}
        />
        <TextField         
          id="currentStatus"
          name="currentStatus"
          label="Current Status"
          placeholder=""
          value={formik.values.currentStatus}
          onChange={formik.handleChange}
          error={formik.touched.currentStatus && Boolean(formik.errors.currentStatus)}
          helperText={formik.touched.currentStatus && formik.errors.currentStatus}
        />
        <TextField         
          id="quote"
          name="quote"
          label="Client Statement"
          placeholder=""
          value={formik.values.quote}
          onChange={formik.handleChange}
          error={formik.touched.quote && Boolean(formik.errors.quote)}
          helperText={formik.touched.quote && formik.errors.quote}
        />
        <TextField         
          id="measurement"
          name="measurement"
          label="Statement of Measurement"
          placeholder=""
          value={formik.values.measurement}
          onChange={formik.handleChange}
          error={formik.touched.measurement && Boolean(formik.errors.measurement)}
          helperText={formik.touched.measurement && formik.errors.measurement}
        />
        <TextField         
          id="plan"
          name="plan"
          label="Plan"
          placeholder=""
          value={formik.values.plan}
          onChange={formik.handleChange}
          error={formik.touched.plan && Boolean(formik.errors.plan)}
          helperText={formik.touched.plan && formik.errors.plan}
        />
        <DialogActions>
          <Button onClick={handleClose}>Cancel</Button>
          <Button color="primary" variant="contained" fullWidth type="submit">
          Submit
        </Button>
      </DialogActions>
      </form>
    )}
      </Formik>
      </DialogContent>
      
    </Dialog>
    </div>
  );
};

I attempted to get more details from the error in a couple of spots, but the only one that logs anything is the .catch after the call and .unwrap() (which is what provided the error referenced above). When I tried error.status or error.data, I just get undefined. But logging the error I get the stack trace with the _a2 is undefined.

React/Next.js , page scroll freezing after opening dialog box

So basically when the user clicks on an image, I am displaying the details of the image as a modal/dialog box. But after the dialog box is closed, the screen scroll freezes. Things work on the screen, but I cant scroll down and access the other elements. Any idea how i can debug.

I feel its because somehow the modal is disabling my scroll bar.

Below is my dialog box code

import React from 'react'
import { Dialog, Transition } from '@headlessui/react'
import { Fragment } from 'react'
import {XIcon} from '@heroicons/react/solid'
import {useRecoilState} from 'recoil'
import {openState} from '../../../atoms/modalAtom'


const product = {
  name: "Women's Basic Tee",
  price: '$32',
  rating: 3.9,
  reviewCount: 512,
  href: '#',
  imageSrc: 'https://tailwindui.com/img/ecommerce-images/product-page-01-featured-product-shot.jpg',
  imageAlt: "Back of women's Basic Tee in black.",
  colors: [
    { name: 'Black', bgColor: 'bg-gray-900', selectedColor: 'ring-gray-900' },
    { name: 'Heather Grey', bgColor: 'bg-gray-400', selectedColor: 'ring-gray-400' },
  ],
  sizes: [
    { name: 'XXS', inStock: true },
    { name: 'XS', inStock: true },
    { name: 'S', inStock: true },
    { name: 'M', inStock: true },
    { name: 'L', inStock: true },
    { name: 'XL', inStock: true },
    { name: 'XXL', inStock: false },
  ],
}

export function DesignQuickView ({design}) {
  const [open, setOpen] = useRecoilState(openState)

  return (
    <Transition.Root show={open} as={Fragment}>
      <Dialog as="div" className="relative z-10" onClose={() => setOpen(false)}>
        <Transition.Child
          as={Fragment}
          enter="ease-out duration-300"
          enterFrom="opacity-0"
          enterTo="opacity-100"
          leave="ease-in duration-200"
          leaveFrom="opacity-100"
          leaveTo="opacity-0"
        >
          <div className="hidden fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity md:block" />
        </Transition.Child>

        <div className="fixed z-10 inset-0 overflow-y-auto">
          <div className="flex items-stretch md:items-center justify-center min-h-full text-center md:px-2 lg:px-4">
            {/* This element is to trick the browser into centering the modal contents. */}
            <span className="hidden md:inline-block md:align-middle md:h-screen" aria-hidden="true">
              &#8203;
            </span>
            <Transition.Child
              as={Fragment}
              enter="ease-out duration-300"
              enterFrom="opacity-0 translate-y-4 md:translate-y-0 md:scale-95"
              enterTo="opacity-100 translate-y-0 md:scale-100"
              leave="ease-in duration-200"
              leaveFrom="opacity-100 translate-y-0 md:scale-100"
              leaveTo="opacity-0 translate-y-4 md:translate-y-0 md:scale-95"
            >
              <Dialog.Panel className="flex text-base text-left transform transition w-full md:max-w-2xl md:px-4 md:my-8 lg:max-w-4xl">
                <div className="w-full relative flex items-center bg-white px-4 pt-14 pb-8 overflow-hidden shadow-2xl sm:px-6 sm:pt-8 md:p-6 lg:p-8">
                  <button
                    type="button"
                    className="absolute top-4 right-4 text-gray-400 hover:text-gray-500 sm:top-8 sm:right-6 md:top-6 md:right-6 lg:top-8 lg:right-8"
                    onClick={() => setOpen(false)}
                  >
                    <span className="sr-only">Close</span>
                    <XIcon className="h-6 w-6" aria-hidden="true" />
                  </button>

                  <div className="w-full grid grid-cols-1 gap-y-8 gap-x-6 items-start sm:grid-cols-12 lg:items-center lg:gap-x-8">
                    <div className="aspect-w-2 aspect-h-3 rounded-lg bg-gray-100 overflow-hidden sm:col-span-4 lg:col-span-5">
                      <img src={design.url} alt={design.name} className="object-center object-cover" />
                    </div>
                    <div className="sm:col-span-8 lg:col-span-7">
                      <h2 className="text-xl font-medium text-gray-900 sm:pr-12">Hoodie</h2>

                      <section aria-labelledby="information-heading" className="mt-1">
                        <h3 id="information-heading" className="sr-only">
                          Product information
                        </h3>

                        <p className="font-medium text-gray-900">{product.price}</p>

                      
                      </section>

                      <section aria-labelledby="options-heading" className="mt-8">
                        <h3 id="options-heading" className="sr-only">
                          Product options
                        </h3>

                        <form>
                          {/* Color picker */}
                          <div>
                            <h4 className="text-sm font-medium text-gray-900">Color</h4>

                            {/* <RadioGroup value={selectedColor} onChange={setSelectedColor} className="mt-2">
                              <RadioGroup.Label className="sr-only">Choose a color</RadioGroup.Label>
                              <div className="flex items-center space-x-3">
                                {product.colors.map((color) => (
                                  <RadioGroup.Option
                                    key={color.name}
                                    value={color}
                                    className={({ active, checked }) =>
                                      classNames(
                                        color.selectedColor,
                                        active && checked ? 'ring ring-offset-1' : '',
                                        !active && checked ? 'ring-2' : '',
                                        '-m-0.5 relative p-0.5 rounded-full flex items-center justify-center cursor-pointer focus:outline-none'
                                      )
                                    }
                                  >
                                    <RadioGroup.Label as="span" className="sr-only">
                                      {color.name}
                                    </RadioGroup.Label>
                                    <span
                                      aria-hidden="true"
                                      className={classNames(
                                        color.bgColor,
                                        'h-8 w-8 border border-black border-opacity-10 rounded-full'
                                      )}
                                    />
                                  </RadioGroup.Option>
                                ))}
                              </div>
                            </RadioGroup> */}
                          </div>

                          {/* Size picker */}
                          <div className="mt-8">
                            <div className="flex items-center justify-between">
                              <h4 className="text-sm font-medium text-gray-900">Size</h4>
                              <a href="#" className="text-sm font-medium text-indigo-600 hover:text-indigo-500">
                                Size guide
                              </a>
                            </div>

                            {/* <RadioGroup value={selectedSize} onChange={setSelectedSize} className="mt-2">
                              <RadioGroup.Label className="sr-only">Choose a size</RadioGroup.Label>
                              <div className="grid grid-cols-7 gap-2">
                                {product.sizes.map((size) => (
                                  <RadioGroup.Option
                                    key={size.name}
                                    value={size}
                                    className={({ active, checked }) =>
                                      classNames(
                                        size.inStock
                                          ? 'cursor-pointer focus:outline-none'
                                          : 'opacity-25 cursor-not-allowed',
                                        active ? 'ring-2 ring-offset-2 ring-indigo-500' : '',
                                        checked
                                          ? 'bg-indigo-600 border-transparent text-white hover:bg-indigo-700'
                                          : 'bg-white border-gray-200 text-gray-900 hover:bg-gray-50',
                                        'border rounded-md py-3 px-3 flex items-center justify-center text-sm font-medium uppercase sm:flex-1'
                                      )
                                    }
                                    disabled={!size.inStock}
                                  >
                                    <RadioGroup.Label as="span">{size.name}</RadioGroup.Label>
                                  </RadioGroup.Option>
                                ))}
                              </div>
                            </RadioGroup> */}
                          </div>

                        </form>
                      </section>
                    </div>
                  </div>
                </div>
              </Dialog.Panel>
            </Transition.Child>
          </div>
        </div>
      </Dialog>
    </Transition.Root>
  )
}

export default DesignQuickView

Here is how i am calling the modal/ dialog box

const Design = ({design}) => {

    const [open, setOpen] = useRecoilState(openState)

    
      return( 

      //Wrapping the image in a card
        <div>
                <div >
                    <img className= "inline-block h-14 w-14 rounded-md " 
                         src={design.url} 
                         alt="Custom design"
                         onClick={()=>setOpen(true)}
                         
                    />

                </div>
                <DesignQuickView design= {design}/>

        </div>
            )
}

export default Design

I think its the scrollbar. Any leads on how i can debug?

Angular application has two different locale for debug and run

I have an application with a calendar that posts a string representation of a timestamp.
I pick a date, let’s assume from a date picker (it’s date-fns and angular-calendar).

I have a POST in my service

  postWorkingSlot(workingSlot: NewWorkingSlot, selectedOperativeID: number)
  {
    let util = new Util();
    workingSlot.starting_time = util.formatDateString(workingSlot.starting_time)
    workingSlot.ending_time = util.formatDateString(workingSlot.ending_time)
    const body = JSON.stringify(workingSlot);
    console.log('Timestamp added : ', body);
    return this.http.post((endpoint + "/" + "api/v1/professional/availability_slot/" + selectedOperativeID ), body, this.httpOptions);
  }

and this is a utility function I am using because I realised that formatDate() has some problems with 12/24h representation.
The weird thing is that for the same date (lets assume the 2nd of July) when I run in debug mode I am getting : 2022-07-02T09:00:00.000+00:00 and when I run with ng serve I am getting 2022-02-07T09:00:00.000+00:00.
You can see this happening in console in the following 2 images :
ng serve
debug

The failure you can see in the first image is 7th of the 15th month (which of course fails). I suspect a problem in the locale settings but what? What am I missing?

Thanks a lot for your time.

Flex JavaScript Object – What Key:Values am I working with?

flex.Actions.addListener accepts an event and passes an object into the Function, as detailed here:

Add an Action after a Task is accepted

console.logging the object just returns: [object Object] and JSON.stringify of the object returns: TypeError: Converting circular structure to JSON.

What is a good method to understand the structure of the object and the information that is available to me when facing the above?

Angular Unit Testing: TypeError: cannot set properties of null (setting ‘innerHtml’) (Jasmine/Karma)

TypeError: cannot set properties of null (setting ‘innerHtml’)

I have created a simple angular service that initializes the inner html of a div tag in the main component of my angular project and is called in multiple components. When I run my tests I get the above karma error. I assume this is because the component is not created in the service.spec.ts file. I have checked and the class is defined in the main html file.

service.ts function:

onCLick(value: string): void {
   document.querySelector('div.class').innerHtml = value;
}

service.spec.ts:

descirbe('ClickedService', () => {
   let service: ClickedService;

   beforeEach(() => {
      TestBed.configureTestingModule({});
      service = TestBed.inject(ClickedService);
   });

   to("#onClick should add to innerHtml", () => {
       service.onClick('test value'); // error is here
   });
});

Hosting of let, const with separate initialization

In Documentaion said that let and const are hoisted.

Variables declared with let and const are also hoisted but, unlike var, are not initialized with a default value. An exception will be thrown if a variable declared with let or const is read before it is initialized.

Also there are a pretty clear sample there:

 console.log(num); // Throws ReferenceError exception as the variable value is uninitialized
 let num = 6; // Initialization

But I don’t understand why this rise the ReferenceError also:

 x = 9
 
 console.log(x)  // Why: "Throws ReferenceError exception as the variable value is uninitialized" here ?

 let x ;

Specs says ‘let’ supports hoising. Initialization is going before using this variable. What’s wrong?
If the reason of the ReferenceError is TDZ then why in specs says that ‘let’ supports hoising, becouse of TDZ and hoising are mutually exclusive things… And what could be an example of hoising for ‘let’ if I can’t use this varibable before declaration…

How to modify an array of objects to new values based on another array in ReactJs?

I have 2 arrays as below, I want to update the array1 value based on array2 value for example in array1.name I want to set it’s value to array2.uName‘s value and updated array should be const array1 = [{name: "aman", age:"26"},...]. How to achieve this in React?

const array1 = [{
    name: "abc",
    age: "123"
  },
  {
    name: "bcd",
    age: "456"
  },
];

const array2 = [{
    uAddress: "India",
    uAge: "26",
    uNum: "12345",
    uName: "aman"
  },
  {
    uAge: "46",
    uAddress: "India",
    uNum: "6789",
    uName: "rohan"
  },
];

I am trying to delete Items from in a TODO-LIST App using Vanilla JavaScript

I have been trying to delete list items from localStorage but nothing happens when I click the delete button. Just to be clear, the delete button was working just fine until I got to the point of trying to delete Items from localStorage. I have a console.log(items) inside deleteFromLocalStorage() to test out if the function is running when I call it inside the deleteItem() which I thought would return some data but still, nothing happens. Please here is the code, help me fix this.

//Deleting Items from the List 
const deleteButton = container.querySelectorAll('.trash-icon');


let deleteItem = (event)=> {
   event.target.parentElement.parentElement.remove();
   deleteFromLocalStorage(item);
}

deleteButton.forEach((button)=> {
    button.addEventListener("click", deleteItem);
});


//SAVING TO LOCAL STORAGE

function savingToLocalStorage(item) {
    let items;
    if(localStorage.getItem("items") === null) {
        items = [];
    } else {
        items = JSON.parse(localStorage.getItem("items"));
    }

    items.push(item);
    localStorage.setItem("items", JSON.stringify(items));
}

//Retrieving From Local Storage 
function retrievingFromLocalStorage(item) {
    let items;
    if(localStorage.getItem("items") === null) {
        items = [];
    } else {
        items = JSON.parse(localStorage.getItem("items"));
    }

    items.forEach((item)=> {
        const todoDIV = document.createElement("div");
        todoDIV.classList.add("todo--item");
        todoDIV.innerHTML = `
        
        <div>
         <input type="radio" name="radio" class="radioBtn">
         <li class="list--item">${item}</li>
         </div>
         <div>
         <i class="fas fa-trash trash-icon"></i>
         </div>
        
        `
        listContainer.appendChild(todoDIV);
    });
}

document.addEventListener("DOMContentLoaded", retrievingFromLocalStorage());


//Delete from Local Storage 

function deleteFromLocalStorage(item) {
    let items;

    if(localStorage.getItem("items") === null) {
        items = [];
    } else {
        items = JSON.parse(localStorage.getItem("items"));
    }
    console.log(item);
}





how to close two nested modals open in react js

Hope you are doing well..
I’m having one small problem in react js and I’m too much confused in this, I’m having one page where I’m opening one modal and inside that modal I’m opening second modal, so the problem here is If I’m clicking outside of the second modal then it will close second modal and it will go to first modal and for first modal If I’m clicking outside then it will go to the main page, so my requirement is if I’m having second modal open and I click outside of the second modal then I should reach to main page not in first modal, I’m attaching JS fiddle link here, you open that link and click on the first modal button and then click on the second modal button and after that click outside of second modal then I should see main page not first modal open, then how to implement this functionality in react js, I can’t share my official code here because it’s private property but I created my own code with html and bootstrap so please help me to solve this problem using javascript or react js, Any suggestion will be very helpful.
Fiddle link

```
http://jsfiddle.net/unto9g0L/
```

after one word is clicked then popup explains it, changes text color to red onmouseover, then changes color back to black onmouseout

I use this script below to change the color for every single word when mouse over that word, and changes back to black when mouse out of that word, and works great. Also, If user want to hear the pronunciation then can click on the word to play the sound, which works great.

There are huge number of words on the text, and for every single word different explanations/popups.

But where im stuck is that i like to add popup over every word onmouseover, and to show explanation for that word only.

I like how it works on html <p title="Explanation">word-1</p> but using js i found difficult to implement.
Also i found an example using css which i like it, but difficult to combine with js.

<script>
   function playAudio(url) {
   new Audio(url).play();
 }
</script>
<p>
<font size="6" style="font-weight:bold;" onmouseover="this.style.color='red';" onmouseout="this.style.color='black';" onclick="playAudio('audio-1.mp3')">first-word</font>
        
<font size="6" style="font-weight:bold;" onmouseover="this.style.color='red';" onmouseout="this.style.color='black';" onclick="playAudio('audio-2.mp3')">second-word</font>
                
<font size="6" style="font-weight:bold;" onmouseover="this.style.color='red';" onmouseout="this.style.color='black';" onclick="playAudio('audio-3.mp3')">third-word</font>
</p>

Vue 3 Intersectionobserver custom directive NOT working

I am trying to define a global intersectionobserver directive in vue 3. My observer looks like the following:

//intersection Observer
const slideAnimation = new IntersectionObserver(
    (entries,slideAnimation) => {
        entries.forEach((entry)=>{
            if(entry.isIntersecting){
                console.log("intersected")

            }
        })
    }
)

export default{
    bind(el){
        slideAnimation.observe(el);
    }
}

in the main.js file i imported this directive and activated it as the following :

import { createApp } from 'vue'
import App from './App.vue'
import slideAnimation from './directives/slideAnimation'


createApp(App).directive('observer',slideAnimation).mount('#app')

and in the HTML template i used it as the following:

<div class="modernisierung-text" v-observer>

but nothing happens…. the test message is not printed, when the element is intersected. Any ideas how to solve this?

Why I am unable to add data to my mongo cluster

So I am trying to make a site to add data in backend by axios and display it but I am unable to add the data to my Mongodb cluster .
Everything is working fine except the Post method .

API call

const url = 'http://localhost:5000/posts';
export const fetchPosts = () => axios.get(url);
export const createPost = (newPost) => axios.post(url, newPost);

reducer

export default (posts = [], action) => {
  switch (action.type) {
    case "FETCH_ALL":
      return action.payload;
    case 'CREATE':
      return [...posts, action.payload];
    default:
      return posts;

action

export const getPosts = () => async (dispatch) => {
    try {
        const { data } = await api.fetchPosts();

        dispatch({ type: 'FETCH_ALL', payload: data });
    } catch (error) {
        console.log(error.message);
    }
}

export const createPost = (post) => async (dispatch) => {
    try {
        const { data } = await api.createPost(post);

        dispatch({ type: 'CREATE', payload: data });

    } catch (error) {
        console.log(error.message);
    }};

the error is 404 but the server is working fine and cluster is showing some spikes when I try to add data in it but it doesn’t create collection

the error

Play a sound when a certain value is selected on slider

I’m trying to make a simple slider that when choosing a certain value on it (in this case 76), the button that says “Continue” plays a certain sound instead of redirecting, but i don’t seem to get it to work, could you guys help me out on this? here is the snippet.

           <div id="Slider">
        <span id="rangeValue">0</span>
        <Input class="range" type="range" name "" value="0" min="0" max="100" onChange="rangeSlide(this.value)" onmousemove="rangeSlide(this.value)"></Input>
    </div>
    <script type="text/javascript">
        function rangeSlide(value) {
            document.getElementById('rangeValue').innerHTML = value;
        }
    </script>
<button class="btn-1" id="i22w3" onclick="play()">Continue</button>
<audio id="audio" src="https://www2.cs.uic.edu/~i101/SoundFiles/BabyElephantWalk60.wav"></audio>
<script type="text/javascript">

var audio = document.getElementById("audio");
      function play() {
        if ('rangeValue' = 76) {
   audio.play();
} else {
   window.location.replace("https://example.com/");
}
        

Thank you in advance!

Javascript : problem with while loop that does not work

In the script below, I’m trying to get a function to find a random number chosen by the system. To help me to find the number :
When the number to find is smaller than what I enter on the interface: I get a message that the number to find is smaller
When the number to find is bigger than the one I enter on the interface: I receive a message that the number to find is bigger
When I find the number, I receive a message telling me that I have found the number in xxx tries. When I find the number in one go, I want to change trial by trial in the message

When I rotate the code below I just have a box to ask me what is the number to guess. Then nothing happens. Can you please help me to fix the code problems in my script below. Could you please also indicate if my approach is correct to count the number of attempts in the code below. How would you proceed ?

function askValue (){
var answer = window.prompt ("Guess the number, enter a number between 1 and 10");
// keep the answer to use it in the loop
if (!answer || isNaN(answer)) {
    console.log("Please enter a valid number");
} else {
    return answer;
}
}



function guessnumber () {
var secret_number = Math.floor (Math.random ()*10) +1;
var guess = askValue ();
var attempts;
var i=0;
var resultMessage = "You won, you take";
while(win==false){
    attempts++;
    if (guess < secret_number){
        console.log("The secret number is bigger");
        i++;
    } else if (guess> Secret_number){
        console.log("The secret number is smaller");
        i++;
    } else if (guess == secret_number) {
        win=true
        if (i == 1){
            var attempt_word = " ";
            attempt_word = "attempt";
        } 
        else if (attempt_word = "attempts"){
            resultMessage += (Number (i)).toString()+ attempt_word;
        }
    }        
console.log (resultMessage);

}
}

// call the function
guessnumber();