Slider bug in html

I was coding in html when I encounterd a simple problem.
I am a beginner so i take most of my stuff from w3schools and for some reason this code did not work.

var slider = document.getElementById("myRange");
var output = document.getElementById("demo");
output.innerHTML = slider.value; // Display the default slider value

// Update the current slider value (each time you drag the slider handle)
slider.oninput = function() {
  output.innerHTML = this.value;
}
div {
    height: 200px;
    width: 400px;
    background: black;

    position: fixed;
    top: 50%;
    left: 16%;
    margin-top: -100px;
    margin-left: -200px;
}
  <link rel="stylesheet" href="uwu.css">
<body>

    <center><h1>How old are you?</h1></center>


  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <div class="slidecontainer">
    <input type="range" min="1" max="18" value="1" class="slider" id="myRange">
  </div>
  <script src="slider.js"></script>

</div>

If you were also wondering jQuery is not added.

How are differences between Node.JS and JavaScript determined?

I watched an interview with Ryan Dahl (the author of Node.JS) in which he discussed that JavaScript Promises was includeded in the first versions of Node.JS, after which it was removed and then returned later on. My question is: How are JavaScript features made part of Node.JS? I thought that Node.JS automatically obtained JavaScript features via being based on the V8 engine. But are JavaScript features being turned on/off selectively? And how do non-vanilla JavaScript features come into Node.JS?

React Native styling the component

i’m building React Native with Expo, trying to make custom dropdown without using liberals, i’m almost done custom dropdown but have some questions

1/i am not sure about using position: 'absolute' and how acts on different screens, also How i could make each dropdown positon on screen flow by it own input view ?

2/ how can i switch between labels so after the user press the item, the item replace and upper with (day / month / year)label ?

this is the UI i want build enter image description here

Dropdown component

const Dropdown = ({ label } ,{data} ) => {
  const [days , setDays] = useState([
    {num: 1 ,key: '1'},
    {num: 2 , key: '2'},
    {num: 3 , key: '3'},
    {num: 4 , key: '4'},
    {num: 5 , key: '5'},
  ]) ;
  const [onSelect, setOnselect] = useState({ label: ''});

  const DropdownButton = useRef();
 const [visible ,  setVisible] =  useState(false);
 
 const [selected, setSelected] = useState(undefined);
 const [dropdownTop, setDropdownTop] = useState(0);


 const toggleFunction = () => {
  visible ? setVisible(false) : openDropdown();
};

const openDropdown = ()=> {
  DropdownButton.current.measure((_fx, _fy, _w, h, _px, py) => {
    setDropdownTop(py + h);
  });
  setVisible(true);
};

const onItemPress = (item) => {
  setSelecte(item);
  onSelect(item);
  setVisible(false);
};

const renderItem = ({ item }) => (
  <TouchableOpacity style={styles.item} onPress={() => onItemPress(item)}>
    <Text>{item.label}</Text>
  </TouchableOpacity>
);
const renderDropdown = () =>{
  return (
    <Modal 
    visible={visible} 
    transparent animationType="none">
      <TouchableOpacity
       style={styles.overlay}
       onPress={() => setVisible(false) }
      >
        <View style={[styles.dropdown, { top: dropdownTop }]}>
        <FlatList
          data={days}
          showsVerticalScrollIndicator = {true}
          renderItem={({item}) => (
            <Text style={styles.item} > {item.num}</Text>
          )}
          
        />
        </View>
        </TouchableOpacity>
      </Modal  > 
  )
}
    return (
    <TouchableOpacity 
    onPress={() => toggleFunction()}
    ref={DropdownButton}
    style={styles.button}>
      <Text> {(onSelect.label) || label}</Text>
      <MaterialCommunityIcons
                  name="chevron-down"
                  color={'#58abc8'}
                  size={16}
                />
     { visible  == true ? ( renderDropdown ()) :null}
    </TouchableOpacity>
    );
  
     }
  const styles = StyleSheet.create({
    button: {
      flexDirection: 'row',
      alignItems: 'center',
      textAlign: 'center',
      fontFamily: 'FrutigerLTArabicRoman',
      height: 40,
      width: '85%',
      zIndex:1,
      justifyContent: 'space-between',
      marginHorizontal: 5,
    },
    buttonText: {
      flex: 1,
      textAlign: 'center',
    },
    dropdown: {
    position: 'absolute',
    left: '5%',
    backgroundColor: '#fff',
    width: '25%',
    height:180,
    shadowColor: '#000000',
    shadowRadius: 4,
    shadowOffset: { height: 4, width: 0 },
    shadowOpacity: 0.5,
    },
    item: {
      paddingHorizontal: 10,
      paddingVertical: 4,
     
    },
  });

WordPress media library with metadata limit

I want to create a media library window. attachment should filter with mime types and metadata.
the mime-type filter is done. How can I build a metadata filter just for this?

function upload_image_tinymce(e) {
    e.preventDefault();
    var $input_field = $('.mce-my_input_image');
    var custom_uploader = wp.media.frames.file_frame = wp.media({
        title: 'Add Video',
        button: {
            text: 'Add Video'
        },
        library: {
            type: [
                'video/MP4',
                'video/quicktime',
                'video/x-m4v',
            ],
        },
        multiple: false
    });
    custom_uploader.on('select', function() {
        var attachment = custom_uploader.state().get('selection').first().toJSON();
        $input_field.val(attachment.id);
    });
    custom_uploader.open();
}

Does React re-executes useState after setState?

If setState trigger a re-rendering of the component, and useState executes for every render, then why does it updates the old value if the initialization is going to be re-executed?

for example, if i have a counter set to 0 (useState(0)) and i modify the state of that counter via setState to 1, that will trigger a re-render therefore useState will be executed again and therefore the value should be zero again, but that does not happen(fortunately) and i don’t know why?

JavaScript scroll manipulation not working on Windows but works on macOS

I’ve been trying to add easing to Website scrolling using native Javscript. This works flawlessly across all browsers on macOS but doesn’t seem to be working in Windows and I’m not quite sure why?

Here is both my Javascript and also an example site that I have used the code in.

Example Site: https://monacograndprix.webflow.io/

  if (window.addEventListener) window.addEventListener('DOMMouseScroll', wheel, false);
  window.onmousewheel = document.onmousewheel = wheel;
  
  function wheel(event) {
      var delta = 0;
      if (event.wheelDelta) delta = event.wheelDelta / 80; //controls how sensitive the scroll wheel is (lower the number = the more sensitive)
      else if (event.detail) delta = -event.detail / 50; 
      handle(delta);
      if (event.preventDefault) event.preventDefault();
      event.returnValue = false;
  }
  
  var goUp = true;
  var end = null;
  var interval = null;
  
  function handle(delta) {
  var animationInterval = 10; // How long it lasts
    var scrollSpeed = 30; // how far it will go
  
  if (end == null) {
    end = $(window).scrollTop();
    }
    end -= 20 * delta;
    goUp = delta > 0;
  
    if (interval == null) {
      interval = setInterval(function () {
        var scrollTop = $(window).scrollTop();
        var step = Math.round((end - scrollTop) / scrollSpeed);
        if (scrollTop <= 0 || 
            scrollTop >= $(window).prop("scrollHeight") - $(window).height() ||
            goUp && step > -1 || 
            !goUp && step < 1 ) {
          clearInterval(interval);
          interval = null;
          end = null;
        }
        $(window).scrollTop(scrollTop + step );
      }, animationInterval);
    }
  }
  
  
  

restrict search times in search box using html codes

I made codes to search in specific items. if you write in the search box ( que ) it will show all the sentenses starting by que ,, like question1 , quesiton2 , question3 , question4 , question5

My purpose is to make search box includes 100 sentenses showing questions and answers in same sentense. and I need users to have limited time of search like making searches for 10 times only for any question they want, out of the 100 questions

those are my codes:

<!DOCTYPE html>
<!-- saved from url=(0055)https://www.NapesterS.com -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>DrNapester ALShemmari</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
  box-sizing: border-box;
}

#myInput {
  background-image: url('/css/searchicon.png');
  background-position: 10px 12px;
  background-repeat: no-repeat;
  width: 100%;
  font-size: 16px;
  padding: 12px 20px 12px 40px;
  border: 1px solid #ddd;
  margin-bottom: 12px;
}

#myUL {
  list-style-type: none;
  padding: 0;
  margin: 0;
}

#myUL li a {
  border: 1px solid #ddd;
  margin-top: -1px; /* Prevent double borders */
  background-color: #0a2351;
  padding: 12px;
  text-decoration: none;
  font-size: 18px;
  color: white;
  display: block
}

#myUL li a:hover:not(.header) {
  background-color: #eee;
}
</style>
</head>
<body>

<h2>DrNapester - TestBank System</h2>

<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Write the question here :)" title="Type in a name">
<ul id="myUL" style="display: none;">
  <li style="display: none;"><a href="Napester.html#">Question1 - (((Answer1)))</a></li>
  <li style="display: none;"><a href="Napester.html#">Question2 - (((Answer2)))</a></li>
  <li style="display: none;"><a href="Napester.html#">Question3 - (((Answer3)))</a></li>
  <li style="display: none;"><a href="Napester.html#">Question4 - (((Answer4)))</a></li>
  <li style="display: none;"><a href="Napester.html#">Question5 - (((Answer5)))</a></li>


<script>
var UL = document.getElementById("myUL");
// hilde the list by default
UL.style.display = "none";

var searchBox = document.getElementById("myInput");

// show the list when the input receive focus
searchBox.addEventListener("focus",  function(){
    // UL.style.display = "block";
});

// hide the list when the input receive focus
searchBox.addEventListener("blur", function(){
    UL.style.display = "none";
});


function myFunction() {
    var input, filter, ul, li, a, i;
    input = document.getElementById("myInput");
    ul = document.getElementById("myUL");
    filter = input.value.toUpperCase();
    // if the input is empty hide the list
    if(filter.trim().length < 1) {
        ul.style.display = "none";
        return false;
    } else {
        ul.style.display = "block";
    }

    li = ul.getElementsByTagName("li");
    for (i = 0; i < li.length; i++) {
        a = li[i].getElementsByTagName("a")[0];

        // This is when you want to find words that contain the search string
     if (a.innerHTML.toUpperCase().indexOf(filter) > -1) { 
        li[i].style.display = "";
     } else {
        li[i].style.display = "none";
    } 

    // This is when you want to find words that start the search string
    /*if (a.innerHTML.toUpperCase().startsWith(filter)) {
        li[i].style.display = "";
    } else {
        li[i].style.display = "none";
    }*/
    }
}
</script>


</body></html>

React-slick Slider doesn’t work, multi-items slider

I prepare a multi-items slider. I used to it react-slick. I implement Slider and add code to show the slider but the functionality doesn’t work.
It should work as a slider of brands (images) for the desktop are 6 of them then the slider should move 6 right or left. The problem is the buttons don’t work. How should I set onlick()?
Why I can set it to solve the functionality of the slider. It loads the website one more time.

JS:

import React, { Component } from 'react';
import Slider from 'react-slick';

import styles from './Brands.module.scss';
import Button from '../../common/Button/Button';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faAngleLeft, faAngleRight } from '@fortawesome/free-solid-svg-icons';

export default class Brands extends Component {
  render() {
  const settings = {
    dots: true,
    infinite: true,
    speed: 500,
    slidesToShow: 1,
    slidesToScroll: 6,
  };
  return (
    <div className={styles.root}>
      <Slider {...settings}>
        <div className='container'>
          <div className='row'>
            <div className={styles.thumbnailNavigationWrapper}>
              <Button className={styles.arrow} variant='small'>
                <FontAwesomeIcon icon={faAngleLeft}>Left</FontAwesomeIcon>
              </Button>
              <div className={styles.thumbnailMenu}>
                <ul>
                  <li>
                    <a href='#' className={styles.activeThumbnail}>
                      <img src='/images/brands/brands-1.jpg' alt='brand'></img>
                    </a>
                  </li>
                  <li>
                    <a href='#'>
                      <img src='/images/brands/brands-2.jpg' alt='brands'></img>
                    </a>
                  </li>
                  <li>
                    <a href='#'>
                      <img src='/images/brands/brands-3.jpg' alt='brands'></img>
                    </a>
                  </li>
                  <li>
                    <a href='#'>
                      <img src='/images/brands/brands-4.jpg' alt='brands'></img>
                    </a>
                  </li>
                  <li>
                    <a href='#'>
                      <img src='/images/brands/brands-5.jpg' alt='brands'></img>
                    </a>
                  </li>
                  <li>
                    <a href='#'>
                      <img src='/images/brands/brands-6.jpg' alt='brands'></img>
                    </a>
                  </li>
                </ul>
              </div>
              <Button className={styles.arrow} variant='small'>
                <FontAwesomeIcon icon={faAngleRight}>Right</FontAwesomeIcon>
              </Button>
            </div>
          </div>
        </div>
      </Slider>
    </div>
  );
}
};


Creating crosshair lines using svg from javascript

I’m trying to create a vertical and horizontal line that will act as a crosshair depending on the position of the mouse. I have cobbled together some code from other stack overflow questions but the lines don’t appear and no error messages are getting logged either. What am I missing?

I’ve added the code below – sorry it’s long adding the html as well as the javascript! I can’t made changes to the html code only to javascript.

javascript code:

export function pick() {

    var hsl = document.createElement("div");
    hsl.className = "hsl";
    document.body.appendChild(hsl);

    var hue = document.createElement("div");
    hue.className = "hue";
    document.body.appendChild(hue);
    hue.style.position = "absolute";

    var luminosity = document.createElement("div");
    luminosity.className = "luminosity";
    document.body.appendChild(luminosity);
    luminosity.style.position = "absolute"

    var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
    //var height = svg.style.height = "100vh";
    //var width = svg.style.width = "100vw";
    svg.id = "svg line";

    document.body.append(svg);

    var verticalLine = document.createElementNS('http://www.w3.org/2000/svg', 'axisY')
    verticalLine.setAttribute("opacity", 0)
    //verticalLine.setAttribute("y1", 0)
    //verticalLine.setAttribute("y2", height)
    verticalLine.setAttribute("stroke", "black")
    verticalLine.setAttribute("stroke-width", 1)
    verticalLine.setAttribute("pointer-events", "none");

    var horizontalLine = document.createElementNS('http://www.w3.org/2000/svg', 'axisX')
    horizontalLine.setAttribute("opacity", 0)
    //horizontalLine.setAttribute("x1", 0)
    //horizontalLine.setAttribute("x2", width)
    horizontalLine.setAttribute("stroke", "black")
    horizontalLine.setAttribute("stroke-width", 1)
    horizontalLine.setAttribute("pointer-events", "none");

    svg.appendChild(verticalLine);
    svg.appendChild(horizontalLine);
    document.getElementById("svg line").appendChild(verticalLine);
    document.getElementById("svg line").appendChild(horizontalLine);


    document.addEventListener(
        "mousemove", function (e) {
            var heightMultiplier = window.screen.height / 100;
            var widthMultiplier = window.screen.width / 360;
            var hueVal = Math.round(e.offsetX / widthMultiplier);
            var luminosityVal = Math.round(e.offsetY / heightMultiplier);
            var hslVal = "hsl(" + hueVal + ", 50%, " + luminosityVal + ")";
            hsl.innerHTML = hslVal
            hue.innerHTML = "hue" + hueVal;
            luminosity.innerHTML = "luminosity" + luminosityVal;
            document.documentElement.style.setProperty('--background', `hsl(${hueVal}, ${50}%, ${luminosityVal}%)`);
            verticalLine.setAttribute("x1", hueVal)
            verticalLine.setAttribute("x2", hueVal)
            verticalLine.setAttribute("opacity", 1);
            horizontalLine.setAttribute("y1", luminosityVal)
            horizontalLine.setAttribute("y2", luminosityVal)
            horizontalLine.setAttribute("opacity", 1)
        });

}

html code:

<!DOCTYPE html>
<html>

<head>
    <title>Pick & click</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link id="fav" rel="shortcut icon" type="image/x-icon" href="data:image/x-icon;,">
    <style>
        :root {
            --background: hsl(0, 0%, 12%);
            --text: hsl(0, 0%, 80%);
            --clear: hsl(0, 0%, 65%);
            --disabled: hsl(0, 0%, 35%);
            --purple: #bb73e6;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: sans-serif;
            letter-spacing: 1.5px;
            background: var(--background);
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            align-content: center;
            width: 100vw;
            height: 100vh;
            padding: 5rem;
            cursor: crosshair;
        }

        svg {
            filter: invert(100%);
            position: fixed;
            width: 100vw;
            height: 100vh;
            top: 0;
            left: 0;
        }

        svg line {
            stroke-width: 0.6px;
            stroke: grey;
        }

        .text {
            position: fixed;
            filter: invert(100%);
            font-size: 50px;
            cursor: pointer;
            white-space: pre-wrap;
        }

        .hsl {
            filter: invert(100%);
            font-size: 17px;
        }

        .hue {
            top: 100px;
            right: 100px;
            text-align: right;
        }

        .luminosity {
            bottom: 100px;
            left: 100px;
        }
    </style>
</head>

<body>
    <script type="module">

        import { pick } from './pick-and-click.js'

        pick()

    </script>
</body>

</html>

Updating the value in array based on condition in javascript

I would like to add/append value filtering based on unique dates and append the value inside latitude value which is inside another object coordinates.

Input:

data = [
  {
    latitude: "1.2",
    longitude: "2.2",
    address: "sadsdasd",
    time_stamp: "04 June 2022 11.23 am"
  },
  {
    latitude: "1.5",
    longitude: "2.5",
    address: "sadsdasd",
    time_stamp: "04 June 2022 11.55 am"
  },
  {
    latitude: "1.7",
    longitude: "2.7",
    address: "sadsdasd",
    time_stamp: "05 June 2022 11.57 am"
  },
  {
    latitude: "1.8",
    longitude: "2.8",
    address: "sadsdasd",
    time_stamp: "05 June 2022 11.58 am"
  },
  {
    latitude: "1.9",
    longitude: "2.9",
    address: "sadsdasd",
    time_stamp: "06 June 2022 11.59 am"
  }
]

Output:

[
  {
    "date": "04-06-2022",
    "coordinates": [{
      "latitude": "1.2",
      "longitude": "2.2"
    },
    {
      "latitude": "1.5",
      "longitude": "2.5"
    }
    ]
  },
  {
    "date": "05-06-2022",
    "coordinates": [{
      "latitude": "1.7",
      "longitude": "2.7"
    },
    {
      "latitude": "1.8",
      "longitude": "2.8"
    }
    ]
  }, {
    "date": "06-06-2022",
    "coordinates": [{
      "latitude": "1.9",
      "longitude": "2.9"
    }]
  }
]

It should filter based on condition and append the value.

How to display images from a JavaScript array in random order

I have tried to show a list of images, but every time the page refreshes the image order change randomly except for the one with a different class name.
I wrote this code but it gives me a duplicate image.

I want 3 things:

  1. display all the images without duplicates.

  2. give them random order every time I refresh the page.

  3. the one with a different class name doesn’t change position.

    .ppl{
    width: 250px;
    }

         var images = [],
         index = 0;
         images[0] = "<img class='ppl pos' src='images/1.jpg' >";
         images[1] = "<img class='ppl pos' src='images/2.jpg' >";
         images[2] = "<img class='ppl pos' src='images/3.jpg' >";
         images[3] = "<img class='ppl n-pos' src='images/g.jpg' >";
         images[4] = "<img class='ppl pos' src='images/4.jpg' >";
    
         function myFunction() {
         for (var i = 0; i < images.length; i++) {
    
         index = Math.floor(Math.random() * images.length);
         document.write(images[index]);
    
             }
         }
         debugger;
    
         myFunction();
         </script>
    

JavaScript localStorage has unexpected values

I’m making a very simple book listing app that is supposed to use localStorage. I have an array of Book objects (using the ES6 class) which is then saved to localStorage using JSON.stringify().

let array = [
    //has Book objects
];

//Book class
class Book {
    constructor(title, author, link, pages) {
        this.title = title;
        this.author = author;
        this.link = link;
        this.pages = pages;
        this.isRead = false; 
    }
}

//saves the array whenever user adds a book listing
function addBook(book, array) {
    array.push(book);
    localStorage.setItem("library", JSON.stringify(array));
}

When I view the content of local storage, it has three additional, unexpected values such as :

darkyMode: "1"
darkyState: "f"
darkySupported: "t"
library: //my array of books

[value of localStorage][1]
[1]: https://i.stack.imgur.com/f8HRS.png

I want to remove these additional values and prevent them from appearing if possible.
Is this normal in javascript? I use bootstrap, and plain JS, if it helps.

track user key pesses in input field in a separate function

I want to track user key pesses in input field in a separate function and call a function based on onkeydown value. What I have below just doesn’t work. Nothing happens. I’m open to eye-opening revelations and commentary. I think I’m missing something major.

`<input onkeydown = "find_key(this,this.id);" id = "P${i}" maxlength = "27" />`;

function find_key (Fval, Fid) {

//prevents malicious characters
if ((event.charCode <= 47) || (event.charCode >= 64)) {return;};

// user presses ctrl + delete
// this doesn't work, nothing happens
if (event.code == 46 && (event.ctrlKey || event.metaKey)) 
{ alert('Undo!'); }

// this doesn't work, nothing happens
if(event.ctrlKey && e.keyCode == 13) {alert ("grab"); grabName(Fval, Fid);}
    
}

Can’t change image to video camera when button clicked

i am new to python and flask and i want to a facemask detection in webapp. But, i faced some problems which is i cannot change the image to video camera when button clicked. Is there anything wrong with my code. Below is my html and python code.

<html>
<head>
    <link rel = "stylesheet" type="text/css" href="/static/style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <script>
        
            function stop(){
                $("#ciao").attr("src", "/static/1.png");
                $("#stop").attr("class","btn btn-danger active");
                $("#start").attr("class","btn btn-outline-success");
            }
            function start(){
                $("#ciao").attr("src", "{{url_for('video')}}");
                $("#start").attr("class","btn btn-success active");
                $("#stop").attr("class","btn btn-outline-danger");
            }
        
                </script>
</head>
    <body>
        <div class="">
        <button id="start" onclick= "start()" class="btn btn-outline-success"><i class="fa fa-video-camera"></i> start</button>
        <button id = "stop" onclick="stop()" class="btn btn-danger active"><i class="fa fa-stop"></i> Stop</button> 
    </div>
        <img id ="ciao" class ="image1" src="/static/1.png">
    </body>
    
App.py
from flask import Flask, render_template,Response
from cameraDetection import Video
app = Flask(__name__)
output=[]
@app.route('/')
@app.route('/FaceMaskDetection_HomePage')
def homepage():
    return render_template("FaceMaskDetection_HomePage.html",result = output)
def gen(camera):
    while True:
    frame=camera.get_frame()
     yield(b'--framern'
     b'Content-Type:  image/jpegrnrn' + frame +
     b'rnrn')
@app.route('/video')
    def video():
     return Response(gen(Video()),
      mimetype='multipart/x-mixed-replace; boundary=frame')
app.run(debug=True)

cameraDetection.py
import cv2
class Video(object):
  def __init__(self):
    self.video=cv2.VideoCapture(0)
  def __del__(self):
    self.video.release()
  def get_frame(self):
    ret,frame=self.video.read()
    ret,jpg=cv2.imencode('.jpg',frame)
    return jpg.tobytes()