Delete Element from the Page

the teacher asked us to design a website to teach children letters, when I click the generate button, it generates letters in a random way, and when I click on a letter, an image of something that starts with this letter is displayed. The problem is when I click on another letter, it displays an image of something that starts with this letter, but The old image of the other letter is still present on the page and is not deleted. What I want is when I click on a letter it displays an image of something that begins with this letter and when I click on another letter I want it to delete the old image and display only the image that begins with this letter
this is my JS code

var div2 = document.getElementById("div2");
var div3 = document.getElementById("div3");
var generate = document.getElementById("generate");
var input = document.getElementById("input"); 
var letters = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
// here to add the path of the each img to array to store it becuase we will need it leter 
litterImg = [];
for (let i = 0;i < 26;i++) {
    litterImg[i] = 'img\'+i+'.jpg';
};
var randomLetter = [];
var getRandomLetter = [];
var linkImg = [];
var numberOfLitters;
generate.addEventListener("click",function(e){ 
    numberOfLitters = input.valueAsNumber;
    for (let index = 0; index < numberOfLitters; index++) { 
        let x = randomNumbers();
        randomLetter[index]  = document.createElement("input");
        randomLetter[index].setAttribute("type","button");
        randomLetter[index].setAttribute("value",letters[x]);
        randomLetter[index].setAttribute("id", x);
        randomLetter[index].setAttribute("class",x);
        div2.appendChild(randomLetter[index]);
    }});
// event to add the images when i click on a litter  
div2.addEventListener("click",function(e){
    for (let index = 0; index < 26; index++) {
        if (e.target.id == index) {
            linkImg[index] = document.createElement("img");
            linkImg[index].setAttribute("src",litterImg[index]);
            linkImg[index].setAttribute("width","1080px");
            linkImg[index].setAttribute("height","720px");
            div3.appendChild(linkImg[index]);
        }
    }
});

and this is my html code

<html>
    <head>
        <meta>
        <title>Alphabet Learner</title>
    </head>
    <body>
        <div id="div" class="div"  style="text-align : center;">
            <h1>Learn the English Litters </h1><br>
            <label >Number of Litters: </label>
            <input type="number" class="input" id="input" >
            <input type="button" class="generate" id="generate" value="Generate">
            <br><br>
            <div id="div2" class="div2">
            </div><br>
            <div id="div3" class="div3"></div>
        </div>
        <script src="script.js"></script>
    </body>
</html>

stuck at default page of WordPress

hello and hope you guys have a fantastic time

I have a problem with my WordPress website, it does now show fallowing elements: my theme, my homepage, my WordPress bar at the top

it just show a empty black blank page with big logo of my website

you can see other part of the website by searching it manually (like: yourname.com/blog)

but not the main home page (like: yourname.com)

please assist me

thanks ❤

jQuery text search – how do I show a “No results” div when using an if else conditional?

I’m working on a “live” text search in the html on a page using jQuery.

The function below works as a “live” search, when a minimum of three characters is entered to start the search.

$('#search').keyup(function() {
    var text = $(this).val().trim();
    var minLength = 2;
    $('.record.active').removeClass("active");
    if (!text.length) return;
    if (text.length > minLength)
    $('.record').each(function() {
      if ($(this).text().toLowerCase().includes(text)) {
        $(this).addClass("active");
      }
    });

But what I want to do is show “No results” when there are no results. I’m trying to use an if else statement to determine if there are any records with the active class. But function in the snippet below doesn’t work; it simply shows “No ResultsNo ResultsNo ResultsNo Results….” with no search results.

 $('#search').keyup(function() {
    var text = $(this).val().trim();
    var minLength = 2;
    $('.record.active').removeClass("active");
    if (!text.length) return;
    if (text.length > minLength)
    $('.record').each(function() {
      if ($(this).text().toLowerCase().includes(text))
        $(this).addClass("active");
        else
        $('.record').not("active");
        $(".no-results").append("No Results");
    
    });
  });
.record {
display: none;
}

.record.active {
display: block;
}
   
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Search <input type='text' id='search' placeholder='Search Text'>

<br />

<div class="no-results"></div>

<br />

<div class="record">Now is the time for all good men to come to the aid of their city</div>
<div class="record">Now is the time for all good women to come to the aid of their country</div>
<div class="record">Now is the time for all droids to come to the aid of their universe</div>
<div class="record">Now is the time for all fluffy bears to come to the aid of their wilderness</div>
<div class="record">Now is the time for all short people to come to the aid of their county</div>

JavaScript Algorithm For Continuous Filtering Data On Most Recent Results

I need to write an algorithm where the user selects an option to filter a particular data and on every click it makes an api request returning the filtered data. As many times the user clicks it needs to continue to filter out the data. My question is, how can the algorithm save the most recent result and run a for/filter loop on the most recent results? And when the user decides to unselect the data that they wanted to filter, it should show the user their previous results. The user should be able to continue to filter until they get the desired data. Please see example below.

***DATA***
let data = [
  {"id":0, "name":"John1", "age":29, "city":"seattle", "score": 95},
  {"id":1, "name":"John2", "age":25, "city":"seattle", "score": 95},
  {"id":2, "name":"John3", "age":29, "city":"seattle", "score": 85},
  {"id":3, "name":"John4", "age":30, "city":"austin", "score": 75},
  {"id":4, "name":"John5", "age":24, "city":"austin", "score": 85},
  {"id":5, "name":"John6", "age":30, "city":"aspen", "score": 84},
  {"id":6, "name":"John7", "age":31, "city":"aspen", "score": 100},
  {"id":7, "name":"John8", "age":31, "city":"aspen", "score": 93},
  {"id":8, "name":"John9", "age":35, "city":"denver", "score": 93},
  {"id":9, "name":"John10", "age":29, "city":"denver", "score": 75},
  {"id":10, "name":"John11", "age":28, "city":"denver", "score": 85},
  {"id":11, "name":"John12", "age":28, "city":"denver", "score": 85},
]
***FIRST USER SELECTED FILTER***
let firstFilter = [{"score":85}]

***FIRST FILTER RESULTS***
let firstFilterdResults = [
  {"id":2, "name":"John3", "age":29, "city":"seattle", "score": 85},
  {"id":4, "name":"John5", "age":24, "city":"austin", "score": 85},
  {"id":10, "name":"John11", "age":28, "city":"denver", "score": 85},
  {"id":11, "name":"John12", "age":28, "city":"denver", "score": 85},
 ]
***SECOND USER SELECTED FILTER***
let secondFilter = [{"age":28}]

***SECOND FILTER RESULTS***
let secondFilterdResults = [
  {"id":10, "name":"John11", "age":28, "city":"denver", "score": 85},
  {"id":11, "name":"John12", "age":28, "city":"denver", "score": 85},
 ]
***CURRENT ALGORITHM***

function filterDataList(data, firstFilter) {
  let firstFilteredResults = [];

  firstFilteredResults = data.filter((dataItem) => {
    var throwVar = 0 
    for (let item of firstFilter) {
      for (let key in item) {
        if (dataItem[key] === undefined || dataItem[key] !== item[key]) {
          throwVar = 0
        } else {
          return true
        }
      }



    }
    if (throwVar == 0) {
      return false
    }
  })

  return firstFilteredData

}

store and read firebase serviceAccountKey from dotenv (.env) file in node js

I’m using firebase in my project and I want to store its serviceAccountKey.json file in .env file like this

SERVICE_ACCOUNT_KEY={
  "type": "service_account",
  "project_id": "abc-123",
  "private_key_id": "123",
  "private_key": "-----BEGIN PRIVATE KEY-----n**some string**n-----END PRIVATE KEY-----n",
  "client_email": "firebase-adminsdk-whatever.gserviceaccount.com",
  "client_id": "123",
  "auth_uri": "https://something",
  "token_uri": "https://something",
  "auth_provider_x509_cert_url": "https://something",
  "client_x509_cert_url": "https://something.com"
}

And I’m reading this in my firebase-config file like this

const admin = require("firebase-admin");
const serviceAccount = process.env.SERVICE_ACCOUNT_KEY;

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: process.env.DATABASE_URL,
});

It says

Failed to parse service account json file: Error: ENOENT: no such file or directory

And then I tried to parse this file like this

const serviceAccount = JSON.parse(process.env.SERVICE_ACCOUNT_KEY)

And now it’s saying

Failed to parse private key: Error: Invalid PEM formatted message.

Please help me storing this json file in .env file

How to create new array from existing array with different structure

I want to reformat the existing array, how can i do it using Javascript or typescript

first array

pdfData: [
         { 
           Id: 1, 
           path:'https//path/pdf1'
         },
         { 
           Id: 1, 
           path:'https//path/pdf2'
         },
         { 
           Id: 2, 
           path:'https//path/pdf1'
         },
         { 
           Id: 2, 
           path:'https//path/pdf2'
         },
        ]

I want to convert this array to following one

data: [
        { 
           Id: 1, 
           links:['https//path/pdf1','https//path/pdf2']
         },
         { 
           Id: 2, 
           links:['https//path/pdf1','https//path/pdf2']
         },

  ]

how to stop Javascript countdown at 0 [duplicate]

I’m trying to create a countdown for a pomodoro app but I don’t know how to stop it when it reaches 0. I’ve tried: clearInterval, minutes.innerHTML = “0”, and adding return with the condition if(minutes <= 0 && seconds <= 0)

       <div class="card work">
        <h2>Work</h2>
        <p id="stopwatch">1:00</p>
        <button id="start">Start</button>
      </div>
    const start = document.querySelector("#start");
    start.addEventListener("click", updateCountdown);

    const startingMinutes = 1;
    let time = startingMinutes * 60;

    const countdownEl = document.querySelector("#stopwatch");

    setInterval(updateCountdown, 1000);

      function updateCountdown() {
      const minutes = Math.floor(time / 60);
      let seconds = time % 60;
      seconds = seconds < 10 ? "0" + seconds : seconds;
      countdownEl.innerHTML = `${minutes}:${seconds}`;
      time--;

      if (minutes <= 0 && seconds <= 0) {
        minutes.innerHTML = "00";
        seconds.innerHTML = "00";
      }
      }

What’s the best way to leverage the event-loop for concurrent work?

I’ve been giving some thought at what could be the best way to deal with a batch of heavy operations with Javascript and I came up with the following:

const results: Promise<void>[] = [];

// Start all pieces of work concurrently
for (const record of await getData()) {
  results.push(doSomeHeavyWork(records));
}

// Collect the results
for (const result of results) {
  // Isolate the failures so one doesn't break another.
  try {
    await result;
  } catch (error) {
    console.log(JSON.stringify(error));
  }
}

My understanding is that the above snippet takes as long as the longest operation, and that’s as good as it’s going to get AFAIK. However, is there a better or more idiomatic way of going about this problem?

I’m not really looking necessarily at node here. This could be node, Deno or browser code.

Make form send email with PHP and jQuery validation – not working

I want a form to send an email where jQuery validates the form and then forwards the data to PHP which should send an email. Only validation works, but nothing else. The jQuery Form Submit script doesn’t work, as well as PHP code. I just can’t figure out what is wrong.

Of course, I know PHP can’t send an email from localhost but I’m using XAMPP for that instance. So it should also work, but the problem is in the code.

// Form Validation - WORKS

$(document).ready(function() {

  $("form").validate({

    errorPlacement: function(error, element) {
      $(element)
        .closest("form")
        .find("label[for='" + element.attr("id") + "'] > span")
        .append(error);
    },

    errorElement: "span",

    rules: {
      firstname: "required",
      lastname: "required",
      email: {
        required: true,
        email: true
      },
      subject: "required",
      msg: "required",
      checkbox: "required",
    },

    messages: {
      firstname: "*required",
      lastname: "*required",
      email: {
        required: "*required",
        email: "*invalid email address"
      },
      subject: "*required",
      msg: "*required",
      checkbox: "*required",
    },

    submitHandler: function(form) {
      form.submit();
    }
  });

});


// Form Submit - DOESN'T WORK

$('form').on('submit', function(e) {

  e.preventDefault();

  $.ajax({
    type: 'post',
    url: 'http://127.0.0.1:5500/php/base.php',
    data: $('form').serialize(),
    success: function() {
      alert('Form was submitted.');
      $('.send').addClass('send-up');
      $('.sent').addClass('sent-up');

      setTimeout(function() {
        $('.send').removeClass('send-up');
        $('.sent').removeClass('sent-up');
      }, 2000);
    }
  });

  return false;

});
.form {
  text-align: right;
  font-family: sans-serif;
  background: #000;
  color: #FFF;
  padding: 50px;
}

form {
  text-align: left;
}

form li {
  position: relative;
  margin-bottom: 55px;
  list-style-type: none;
}

.li-firstname,
.li-lastname {
  width: 44%;
  display: inline-block;
}

.li-firstname {
  margin-right: 68px;
}

input,
textarea {
  background: transparent;
  border: 0;
  outline: 0;
  border-bottom: 2px solid #FFF;
  display: block;
  color: #FFF;
  width: 100%;
  padding: 15px 0 15px 30px;
  box-sizing: border-box;
  transition: border-bottom 0.3s ease-in-out;
  resize: none;
}

.label {
  position: absolute;
  right: 0;
  margin-top: 10px;
}

form i {
  position: absolute;
  bottom: 16.5px;
  transition: color 0.3s ease-in-out;
}

.submit {
  outline: 0;
  border: 0;
  color: #FFF;
  padding: 0;
  width: 243px;
  height: 60px;
  cursor: pointer;
  position: relative;
  background: #704DFA;
  border-radius: 50px;
  text-transform: uppercase;
}

.submit span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: all 0.7s ease-out;
}

.send-up {
  margin-top: -30px;
  opacity: 0;
}

.sent {
  margin-top: 30px;
  opacity: 0;
}

.sent-up {
  margin-top: 0;
  opacity: 1;
}

input:focus,
textarea:focus {
  border-bottom: 2px solid #704DFA;
}

input:focus+i,
textarea:focus+i {
  color: #704DFA;
}

span.error {
  font-family: sans-serif;
  font-style: italic;
  font-size: 13px;
  color: #704DFA;
  margin-right: 10px;
}

span.error:not(#checkbox-error) {
  float: left;
  margin-right: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.1/jquery.validate.min.js"></script>
<script src="https://kit.fontawesome.com/a671c6b423.js" crossorigin="anonymous"></script>

<div class="form">
  <form id="form">
    <ul>
      <li class="li-firstname">
        <input type="text" name="firstname" id="firstname" required>
        <i class="far fa-user"></i>
        <label for="firstname" class="label"><span>First Name</span></label>
      </li>
      <li class="li-lastname">
        <input type="text" name="lastname" id="lastname" required>
        <label for="lastname" class="label"><span>Last Name</span></label>
      </li>
      <li class="li-email">
        <input type="email" name="email" id="email" required>
        <i class="far fa-envelope"></i>
        <label for="email" class="label"><span>Email Address</span></label>
      </li>
      <li class="li-subject">
        <input type="text" name="subject" id="subject" required>
        <i class="far fa-question-circle"></i>
        <label for="subject" class="label"><span>Subject</span></label>
      </li>
      <li class="li-message">
        <textarea name="msg" id="msg" wrap="hard" rows="5" maxlength="2000" required></textarea>
        <i class="far fa-comment-dots"></i>
        <label for="msg" class="label"><span>Job Proposal</span></label>
      </li>
      <li class="li-checkbox">
        <input type="checkbox" name="checkbox" id="checkbox" required>
        <label for="checkbox">
You want to work with me specifically because you feel my style fits perfectly to your business.
       </label>
      </li>
    </ul>
  </form>

  <button class="button submit" type="submit" form="form">
     <span class="send">Submit</span>
     <span class="sent">Sent</span>
  </button>
</div>
<?php

  $firstname = $_POST['firstname'];
  $lastname = $_POST['lastname'];
  $visitor_email = $_POST['email'];
  $visitor_subject = $_POST['subject'];
  $message = $_POST['msg'];
  $checkbox = $_POST['checkbox'];


  $email_from = '[email protected]';

  $email_subject = $visitor_subject;

    $email_body = "You have received a new message from the user $firstname $lastname.n".
                            "Here is the message:n $message".

                            
  $to = "[email protected]";

  $headers = "From: $email_from rn";

  $headers .= "Reply-To: $visitor_email rn";

  mail($to,$email_subject,$email_body,$headers);

?>

Randomly place images and move their position on hover [closed]

I need foxes to randomly spawn in a certain place in the bush. When you hover the mouse over a bush where there is a fox, the fox should hide and random spawn on other place.

let item1 = document.createElement('div');

item1.className = "item1";
item1.innerHTML = '<div class="lisa1"><img src="*https://forumstatic.ru/files/0019/3c/8c/22179.png?v=1"></div><div class="kust1"><img src="*https://forumstatic.ru/files/0019/3c/8c/35365.png?v=1"></div>';
document.body.append(item1);

let item2 = document.createElement('div');

item2.className = "item2";
item2.innerHTML = '<div class="lisa2"><img src="*https://forumstatic.ru/files/0019/3c/8c/62333.png"></div><div class="kust2"><img src="*https://forumstatic.ru/files/0019/3c/8c/67140.png"></div>';
document.body.append(item2);

let item3 = document.createElement('div');

item3.className = "item3";
item3.innerHTML = '<div class="lisa3"><img src="*https://forumstatic.ru/files/0019/3c/8c/50942.png"></div><div class="kust3"><img src="*https://forumstatic.ru/files/0019/3c/8c/56314.png"></div>';
document.body.append(item3);