get “clear is not a function” from console on chrome dev tool

I hope anyone could help me understand this situation.
So, I wanted to clear the console after trying some simple codes like…

const smt = {printThis(){console.log(this)}};
smt.printThis();

and then typed clear as always, to clear it.

But then got this error saying clear is not a function.
And when typed clear and pressed enter, it shows tag. …?

I really want to know what this is about, and hopefully someone knows about it.
Just in case it’s already been asked here, really sorry if my searching wasn’t enough.

clearIsNotAFunction

I want to fetch a code value into a div in html format, knowing that this code is in a link

I want to fetch code value from json file url to div in html format

{“ckack”:”success”,”code”:”rn <script type=”text/javascript”>rn $(“#process-waiting”).css(‘display’,’none’);rn if(typeof iWorker != ‘undefined’){rn clearInterval(iWorker);rn iWorker = undefined;rn }rnrn</script>rn
<div class=”form-group has-success has-feedback”>rn
<a href=”https://domain.com/?file=M3R4SUNiN” rel=”nofollow” type=”button” class=”btn btn-success btn-file”>rn
<i class=”glyphicon glyphicon-download-alt”></i>  Download </a>rn</div>”}

JS create a new date based on different interval types

I am trying to make JavaScript that creates a new date based on a certain interval that could be either years, months, days or hours. I would like to create a new date with time depending on interval type. I don’t really know how to start.

    var startDate = 2022-04-19T10:00:00.000Z
    var interval = 10
    var intervalType = "days" // could be Months, Days, Hours

How to add animation?

How will I add fadeout animation in this javascript code?

document.getElementById("mt-alerts").style.display="block";
setTimeout(function(){
    document.getElementById("mt-alerts").style.display="none";
}, 2000);

GET http://localhost:3000/search 404 (Not Found)REACT.JS, Node.js and Axios

Can Anyone help me please?
I’m trying to build a youtube clone website, but I get this error:

GET http://localhost:3000/search 404 (Not Found)
Uncaught (in promise) Error: Request failed with status code 404
at createError (createError.js:16:1)
at settle (settle.js:17:1)
at XMLHttpRequest.onloadend (xhr.js:66:1)

App.js:

import React from "react";
import axios from "axios";
import { Grid } from "@material-ui/core";
import { SearchBar, VideoDetail } from "./components";

import youtube from "./api/youtube";

class App extends React.Component {
  state = {
    video: [],
    selectedVideo: null,
  };
  handleSubmit = async (searchTerm) => {
    const response = await axios.get(""http://localhost:3000/search", youtube, {
      params: {
        part: "snippet",
        maxResults: 5,
        q: searchTerm,
      },
    });

    this.setState = {
      videos: response.data.items,
      selectedVideo: response.data.items[0],
    };
  };
  render() {
    const { selectedVideo } = this.state;
    return (
      <Grid justifyContent="center" container spacing={10}>
        <Grid item xs={12}>
          <Grid container spacing={10}>
            <Grid item xs={12}>
              <SearchBar onFormSubmit={this.handleSubmit} />
            </Grid>
            <Grid item xs={8}>
              <VideoDetail video={selectedVideo} />
            </Grid>
            <Grid item xs={4}>
              {/*VIDEO DETAILS */}
            </Grid>
          </Grid>
        </Grid>
      </Grid>
    );
  }
}

export default App;

searchBar.js:

import React from "react";

import { Paper, TextField } from "@material-ui/core";

class SearchBar extends React.Component {
  state = {
    searchTerm: "",
  };

  handleChange = (event) => {
    this.setState({ searchTerm: event.target.value });

    this.handleSubmit = (event) => {
      const { searchTerm } = this.state;
      const { onFormSubmit } = this.props;

      onFormSubmit(searchTerm);

      event.preventDefault();
    };
  };
  render() {
    return (
      <Paper elevation={6} style={{ padding: "25px" }}>
        <form onSubmit={this.handleSubmit}>
          <TextField
            fullWidth
            label="Search..."
            onChange={this.handleChange}
          ></TextField>
        </form>
      </Paper>
    );
  }
}

export default SearchBar;

youtube.js:

import axios from "axios";
const key = "MY_API_KEY";
export default axios.create({
  baseURL: "https://googleapis.com/youtube/v3",
});

Can someone please tell me what is wrong here?

How to skip a specific Div-Area while replacing text in DOM-Nodes

A browser add-on replaces some words on a website. This part works! Now I want to skip a specific area on the site. How can I skip/exclude anything within “” or “”?

The pages structure is this:

<html>
<body id="chat">
[...]
<div id="chatBar">
  <ul class="chat_bar_list">
   [...]
   </ul>
</div>
[...]
</body>
</html>

This part does the replacement-job:

function replaceText (node) {
    if (node.nodeType === Node.TEXT_NODE) {
        // My try to skip specific area here (doesn't work)
        //if (document.getElementById("chatBar")) {
        //  return;
        //}
        let content = node.textContent;
        for (let [word, emoji] of langMap) {
          const regex = regexs.get(word);
          content = content.replace(regex, emoji);
        }
        node.textContent = content;
  }
  else {
    // This node contains more than just text, call replaceText() on each
    // of its children.
    for (let i = 0; i < node.childNodes.length; i++) {
      replaceText(node.childNodes[i]);
    } 
  }
}
replaceText(document.body);

Is my modulo use wrong or is there a Math.floor rounding error happening with my seconds to minutes calculation?

Am writing code to split seconds into years, days, minutes, seconds. I’m getting some unexpected results: eg 3600 seconds comes out as 1 hour. But 3599 seconds comes out as 60 minutes and 59 seconds.

Firstly, there should never be 60 minutes. This should be 1 hour. But that aside the actual result is wrong.

Is there some error in my calculation logic, or is there a funky rounding error going on using modulo and Math.floor? Thanks!

  function convertFromSeconds(time) {

  const minute = 60
  const hour = 60 * minute; //3600
  const day = 24 * hour; // 86400
  const year = 365 * day //31536000
  
  const years = Math.floor(time / year)
  const days = Math.floor((time % year) / day)
  const hours = Math.floor((time % day) / hour)
  const minutes = Math.floor((time % hour) / minute)
  const seconds = time % minute;

  // Rest of code formats the above result into a string for output
}

Want to remove objects that are before specific value

const array = [
{ id: "U", 
T: "001"},
{ id: "R", 
T: "002"},
{ id: "U", 
T: "003"},
{ id: "R", 
T: "004"},
{ id: "U", 
T: "005"},]

Above array can have multiple objects with id: 'R' and i want to ignore all objects that are before id: 'R'.

Expected:

const array = [
{ id: "U", 
T: "005"}]

Can someone please help with this

React js how to save the state of each inline input from a table?

I have a html table in react with columns containing student data and the final row containing an input when you can input the marks they got. I was wondering how I could save the state of each row without having to manually create a new state for each student as that would be inefficient as there’s always a different amount of students.

Thank you for any help!

my d3.js graph is not fetching the value from csv file

I have made an interactive line chart graph where i am showing about different indian year-wise ministries budget where i have stored my data in csv file which was loaded to the d3.js but on initializing i can only see the axis and not the line . help me to identify the issue.
i have tried to change the values and put the names of the columns in the code but it is not working .

Code:https://github.com/keertanbhatt/d3_project

How can we proramatically generate vega grammar JSON from vega-lite plot?

I am able to get vega json grammar on local installation of nodejs with vega-lite and vega-lite-api installed through npm as follows:

vl = require('vega-lite') 
vla = require('vega-lite-api') 
data = require('vega-datasets') 

const df2 = data['movies.json']()

const plot = vla.markBar().data(df2).encode(
    vla.x().fieldQ('IMDB_Rating').bin(true),
    vla.y().count()
  )

vega_lite_json = plot.toObject();
vega_json = vl.compile(plot.toObject()).spec;

However I am unable to make it work in Observablehq.

I am not able to do last line: vl.compile(...).
This is what I have did:

vegalite = require("@observablehq/[email protected]")
vegalite.compile(plot.toObject()).spec;

It says: TypeError: vegalite.compile is not a function
Here is link to my observablehq notebook cell executing vegalie.compile(...).

What I am doing wrong?

how to run npm start without opening browser for react development on linux

Hello everyone 🙂 noob here,

i am learning react and find myself running npm start on the terminal a couple of times but its annoying how it opens a new browser window everytime. I’m trying to stop this from happening on linux.

I found a solution for how to do this on windows(https://siderite.dev/blog/running-npm-start-without-opening-browser/) but how do i do it on linux

make new interval when clicking on next or previous button on a slide

I have made an auto slide with interval of 8s, then i’ve added a previous and a next button that work but my problem now is that the interval is of course still running. Instead of that, I would like to make new interval each time I click on a button. Could someone help me please ? Thank you in advance 🙂 have a good day

javascript

const prev = document.querySelector('.slider .fa-chevron-circle-left');
const next = document.querySelector('.slider .fa-chevron-circle-right');

setInterval(function() {
    var active = document.querySelector('.show');
    active.classList.remove('show');
    if (active.nextElementSibling && active.nextElementSibling !== next && active.nextElementSibling !== prev) {
        active.nextElementSibling.classList.add('show');
    } else {
        active.parentElement.firstElementChild.classList.add('show');
    }    
}, 8000);
    
next.addEventListener('click', function() {
    var nextSlide;
    var active = document.querySelector('.show');
    active.classList.remove('show');
    nextSlide = active.nextElementSibling && active.nextElementSibling !== next && active.nextElementSibling !== prev ? active.nextElementSibling.classList.add('show') : active.parentElement.firstElementChild.classList.add('show');
})

prev.addEventListener('click', function() {
    var prevSlide;
    var active = document.querySelector('.show');
    active.classList.remove('show');
    prevSlide = active.previousElementSibling && active.previousElementSibling !== next && active.previousElementSibling !== prev ? active.previousElementSibling.classList.add('show') : active.parentElement.children[2].classList.add('show');
})

html

 <div class="slider">
    <div class="slide show"></div>
    <div class="slide"></div>
    <div class="slide"></div>
    <i class="fas fa-chevron-circle-left"></i>
    <i class="fas fa-chevron-circle-right"></i>
</div>