error: bad operand types for binary operator ‘<'

Hello so I am currently a beginner trying to learn Java and I keep getting this error and have no idea how to change it, this is what I get

Main.java:11: error: bad operand types for binary operator ‘<‘
System.out.println(“(2x + y/2 < z) is ” + 2 * x + y / 2 < z);
^
first type: String
second type: double
1 error

please help!!

public class Main 
{ public static void main(String[] args) { 
    double x, y, z; 
    java.util.Scanner input = new java.util.Scanner(System.in); 
    x = input.nextDouble(); 
    y = input.nextDouble(); 
    z = input.nextDouble(); 
    System.out.println("(x > y && y < z) is " + (x > y && y < z));
    System.out.println("(x > y II y < z) is " + (x > y || y < z)); 
    System.out.println("!(x >= y) is " + !(x >= y));
    System.out.println("(2x + y/2 < z) is " + 2 * x + y / 2 < z); 
    input.close(); 
} 
}

Stomp Client in Web Browser without Websockets

I have a Node.js app in which I use stomp-client to connect and subscribe to an ActiveMQ topic without websockets. My code is the same as this example: https://www.npmjs.com/package/stomp-client#super-basic-example.

Now, I want to do the same thing, but with a Vue.js application. So, I want to subscribe to an ActiveMQ topic in the browser (i.e., in JavaScript, not in Node.js). My ActiveMQ is not configured to support websockets. Is it possible to do this in a browser without websockets?

This is the error I’m getting:
enter image description here

Algorithm for drawing a “Squiggly wiggly” pattern

I’m looking to have an algorithm that can randomly draw a “squiggly wiggly” pattern as per the picture.

enter image description here

It would be nice if it were progressively drawn as you would draw it with a pen and if it were based on speed, acceleration and forces like a double pendulum animation might be.

This would be for javascript in the p5 library.

Is there some way of producing this that a) looks hand drawn and b) fills a page, somewhat like a Hilbert curve?

Very interested to hear ideas of how this could be produced, regardless of whether there is some kind of formal algorithm, although a formal algorithm would be best.

Cheers

why does index.html keep opening as https://www.google.com/index.html?

Im trying to check for a keyword in the url and launch an html file from javascript

here is my code:

window.setInterval(function doTheTing() {
        if (window.location.href.indexOf("keyword") > -1) {
            window.location.replace("index.html")
        }
    }, 1000)

what im trying to do is open the file when the keyword is in url, and it does work, but for some reason when i try to open index.html it opens https://www.google.com/index.html instead

*if the keyword is in the url of a youtube video than it opens as https://www.youtube.com/index.html (which isnt a real domain so it just shows an error page)

*if its from a tiktok than https://www.tiktok.com/index.html (which also returns an error page)

and so on…

how can i just open index.html?

thanks for the help

React update child component when non-state value in parent changes

I’m working on the product pages for an ecommerce React app. The products may have several options that the customer may need to fill in. When complete, the customer will click add to cart and the form will submit.

For validation purposes, the form on the product page needs to know which options are required and filled in. I don’t want to use state here, because then the entire form will re-render every time the customer makes a choice, causing noticeable lag. Even something as simple as typing text into a textfield will trigger a re-render on every keystroke. Instead, the options are in child components with their own state, and re-rendering just the little option component does not cause the page to lag.

So now I’m trying to use useRef in the parent component to store the options’ required/validity status. The parent has a receiver function that receives the option value from the child, and this is passed down to the child. When the child option changes, it calls the receiver function, and the parent receives the data and stores it in a ref array, so each option has an entry in the array.

This all works fine. The parent knows the option values, and which are valid / invalid, etc, so when the user attempts to submit the form, the parent can tell them if they missed something.

The problem is that I want to highlight the invalid options. This means the child that renders the option needs to know if the option is valid or not. But updating the ref in the parent doesn’t trigger a re-render of the child. I knew this would happen but I thought I could figure a way around it. So far, no luck 🙁

So, is there a better way to do this, other than useState and useRef? I’m still somewhat new to React so I’m sure there are a lot of advanced hooks etc that I still need to learn.

Note that I did, for argument’s sake, switch the ref to a piece of state. It worked and the child options re-rendered, but there was horrifying lag when the customer typed into text fields, so that’s out.

Anyway, here’s some of the relevant code from the parent:


let ref_optionValidity = useRef([]);

let adjustOptionValidity = useCallback((options,code="",newValue="") => {
   let optionValidities = [...ref_optionValidity.current];

   options.forEach((option,rowIndex)=>{
      let value = optionValidities[rowIndex] ? optionValidities[rowIndex].value : option.value || "";
      if ( option.code === code ) {
         value = newValue;
      }
      let isValid = option.required && !value ? false : true;
      if ( !optionValidities[rowIndex] ) {
         optionValidities.push({
            isValid:isValid,
            value:value,
            code:option.code
         });
      } else {
         optionValidities[rowIndex].value = value;
         optionValidities[rowIndex].isValid = isValid;
      }
   });
   ref_optionValidity.current = [...optionValidities];
},[]);

return (
   <Options
      ...
      optionValidity={ref_optionValidity}
      adjustOptionValidity={adjustOptionValidity}
   />
);

On the child I just have a simple useEffect to test if the child will pick up the change to the ref, and as expected, it doesn’t.

useEffect(()=>{
   console.log("useEffect running");
},[
   optionValidity.current[rowIndex].isValid
]);

javascript change attribute wont take effect after attribute set on load

i have a problem hopw sombody can help.
i rendered a page with a css class fade-in effect on images.
so when i load the page i have 4 images that load and they have a fade in effect.
now i have a button that when clicked it changes an image and i want to have the same effect on the new image that appear.

here is the html code

<div class="card d-flex justify-content-center ml-3 mr-3 mt-3" style="width: 18rem;">
        <img id="card-num-1" src="/static/TarotCards/tarot-back/tarot-back.jpg" class="card- 
             img-top fade-in-onload" alt="..." style="width: 180px;height: 300px; margin-left: 
             18%;">
        <div class="card-body justify-content-center">
            <h5 class="card-title">Card title</h5>
            <p id="wow" class="card-text">Some quick example text to build on the card title 
             and make up the bulk of the card's content.</p>
            <button id="reveal-1" onclick="card_reveal_1()" class="btn btn-outline-dark 
            ">reveal</button>
            <button id="replace_1" onclick="replaceCard_1()" disabled="true" class="btn btn- 
            outline-dark rep">replace</button>
        </div>
    </div>

my javascript code is

function card_reveal_1() {;

        document.getElementById("card-num-1").setAttribute("src", `/{{ cards[0]["CARD_PATH"] 
        }}`);
        let toDisable = document.createAttribute("disabled");
        toDisable.value = "true";
        document.getElementById("reveal-1").setAttribute("disabled", "true");

        //  -------- that is the place that the set attribute happen ------ 
        
        let fade = document.getElementsByClassName("card-img-top")
        fade[0].setAttribute("class", "card-img-top wow wow fade-in-image")

        // --------------------------------------
        indicator += 1;
        if (indicator == 4) {
            let toEnable = document.getElementsByClassName("rep");
            for (let i = 0; i < toEnable.length; i++) {
                toEnable[i].removeAttribute("disabled")
            }
        }

    }

my problem is that when i look at the dev-tools in the browser it gets updated.
but there is no fade in effect.

i tried to do it with creating attribute and changing with setattribute node.
i tried to remove the class and set it again.

Python Web Development

Like Javascript has ReactJS framework for Frontend development and NodeJS for Backend Development .But Python has Django Framework for backend Development But Why it doesn’t have any Frontend Framework?

How to sort array of object by string of numbers and special characters

I have an array of some objects and I want to sort them by dimension property, where that property is a string of some number intervals and special characters. Here is the example of what I have

let data = [
  {
    "soldTickets": 206,
    "soldRevenue": 12825.309997558594,
    "playedOffTickets": 2915,
    "playedOffRevenue": 495923.22019958496,
    "dimension": "10 - 25",
    "ticketsChange": -2709,
    "revenueChange": -483097.91020202637
  },
  {
    "soldTickets": 172,
    "soldRevenue": 17174.29998779297,
    "playedOffTickets": 2485,
    "playedOffRevenue": 467017.27951049805,
    "dimension": "25 - 50",
    "ticketsChange": -2313,
    "revenueChange": -449842.9795227051
  },
  {
    "soldTickets": 122,
    "soldRevenue": 9892.249984741211,
    "playedOffTickets": 9121,
    "playedOffRevenue": 1129196.3203125,
    "dimension": "> 200",
    "ticketsChange": -8999,
    "revenueChange": -1119304.0703277588
  },
  {
    "soldTickets": 52,
    "soldRevenue": 3159.239990234375,
    "playedOffTickets": 544,
    "playedOffRevenue": 88893.0400390625,
    "dimension": "0 - 10",
    "ticketsChange": -492,
    "revenueChange": -85733.80004882812
  },
  {
    "soldTickets": 38,
    "soldRevenue": 3162.1099700927734,
    "playedOffTickets": 476,
    "playedOffRevenue": 92432.79023742676,
    "dimension": "100 - 200",
    "ticketsChange": -438,
    "revenueChange": -89270.68026733398
  },
  {
    "soldTickets": 37,
    "soldRevenue": 3233,
    "playedOffTickets": 590,
    "playedOffRevenue": 97645.46026611328,
    "dimension": "50 - 100",
    "ticketsChange": -553,
    "revenueChange": -94412.46026611328
  }
];

const toNumber = (str) => {
  if (Number(str)) {
    return Number(str);
  } else {
    return Number(str.substring(0, str.length - 1));
  }
};

   data = data.sort(
        (a, b) =>
          toNumber(String(a["dimension"]).split(' ')[0]) -
          toNumber(String(b["dimension"]).split(' ')[0])
      );
      
  console.log(data)

The problem is that the array is not sorted the way I wanted, since the > 200 should be the last in this case instead of being the first. The desired order should be like this

['0 - 10', '10 - 25', '25 - 50', '50 - 100', '100 - 200', '> 200']

What am I doing wrong? Thanks in advance!

Using a regex to test for for n lowercase characters?

How do we go about creating a regular expression that tests for n lowercase characters in a string?

So for a minimum of 2 characters for example, I thought something like ([a-z]){2,} might work.

For the below test the first two are expected to pass:

const min = 2;
const tests = ['a2a#$2', 'a2a#$2a2', 'a2'];
const regex2: RegExp = new RegExp(`([a-z]){${min},}`);
tests.forEach((t) => {
  const valid = regex2.test(t);
  console.log(`t: ${t} is valid: ${valid}`);
});

Thoughts?

full text search by filter in VueJs

I tried to create simple text search, but I couldn’t execute it. first I got all user data whom provide services and store it inside searchable array, then I tried to to filter it based on user entry.
here you can see my code:

<template>
  <div class="text-h4 text-grey-9">
    <q-input
      outlined
      filled
      type="text"
      v-model="searchResult"
      color="amber-10"
      placeholder="search for service providers"
    />
  </div>
</template>
<script>
import { ref } from "vue";
import { db } from "src/boot/firebase";
import { collection, query, where, getDocs } from "firebase/firestore";

export default {
  setup() {
    return {
      searchableDate: ref([]),
      searchResult: '',
    };
  },
  async created() {
    const q = query(
      collection(db, "userProfile"),
      where("provider", "==", true)
    );
    const serviceProviderSnapshot = await getDocs(q);
    serviceProviderSnapshot.forEach(doc => {
      let docData = doc.data();
      this.searchableDate.unshift(docData);
    });
    console.log(typeof(this.searchableDate))
  },

  computed:{
    searchServiceProvider(){
      let searchResult = []
      if(this.searchResult !== 0){
        searchResult = this.searchableDate.filter(p =>
        p.fullName.toLowerCase().includes(this.searchResult.toLowerCase()) ||
        p.skillCatgs.toLowerCase().includes(this.searchResult.toLowerCase()))
      } else {
        searchResult = this.searchableDate
      }
    }
  }
};
</script>

here is the searchableData format:{0: {…}, 1: {…}, 2: {…}, 3: {…}}

How to reformat json as nested json by parent_id

Here is the Json array, Every object has is_parent and parent_id properties,
If and object has children objects then it’s is_parent property is 1 and vice versa.

let list = [
    {id: 4, name: 'dd', is_parent: 1, parent_id: 0},
    /**/{id: 5, name: 'ee', is_parent: 0, parent_id: 4},
    /**/{id: 6, name: 'ff', is_parent: 1, parent_id: 5},
    /**//**/{id: 7, name: 'gg', is_parent: 0, parent_id: 6},

    {id: 8, name: 'hh', is_parent: 1, parent_id: 0},
    /**/{id: 9, name: 'ii', is_parent: 0, parent_id: 8},

    {id: 10, name: 'jj', is_parent: 1, parent_id: 0},
    /**/{id: 11, name: 'kk', is_parent: 1, parent_id: 10},
    /**//**/{id: 12, name: 'll', is_parent: 1, parent_id: 11},
    /**//**//**/{id: 13, name: 'mm', is_parent: 0, parent_id: 12},
],

I want to format above json array as below

let array = [
    {
        id: 4,
        name: 'dd',
        is_parent: 1,
        parent_id: 0,
        children: [
            {id: 5, name: 'ee', is_parent: 0, parent_id: 4},
            {
                id: 6,
                name: 'ff',
                is_parent: 1,
                parent_id: 5,
                children: [
                    {id: 7, name: 'gg', is_parent: 0, parent_id: 6}
                ]
            }
        ]
    },

    {
        id: 8,
        name: 'hh',
        is_parent: 1,
        parent_id: 0,
        children: [
            {id: 9, name: 'ii', is_parent: 0, parent_id: 8}
        ]
    },

    {
        id: 10,
        name: 'jj',
        is_parent: 1,
        parent_id: 0,
        children: [
            {
                id: 11,
                name: 'kk',
                is_parent: 1,
                parent_id: 10,
                children: [
                    {
                        id: 12,
                        name: 'll',
                        is_parent: 1,
                        parent_id: 11,
                        children: [
                            {id: 13, name: 'mm', is_parent: 0, parent_id: 12}
                        ]
                    }
                ]
            }
        ]
    },
]

I tried to do this by foreach loop inside another foreach loop but it didn’t work

(Javascript How to use a function result as a parameter in another function [duplicate]

I’m currently trying to write a script to be embedded in a HTML file that:

  1. Calls an API for a ticket
  2. Uses the ticket in a subsequent function to display a dashboard

I’m kinda new to Javascript and learning as I go, but I’m getting a bit lost on this one 🙂

Function1 below shows my efforts to store the ticket as a variable. However, when I try to use the ticket in Function2, it appears that the API call hasn’t finished yet.

How can I make Function2 wait for Function1 to complete before processing?

Function1

function getTix() {
    return new Promise(function (resolve) {
        axios.get(api_url)
            .then(response => {
                resolve(response.data.ticket);
                console.log(response.data.ticket);
                myticket = response.data.ticket;
            })
            .catch(error => console.error(error));
    });
}


Function2

function showDashboard() {
    const dash_div = document.getElementById('displaydash');
    const dash_url = "https://server.com/" + myticket;
    
    viz = new Viz(dash_div, dash_url);
}

What next to do in nodejs? [closed]

I have learnt beginner level javascript and now understand nodejs as well but i cant think of a small project or some exercise to do to get a bit more comfortable with nodejs nor can i think of other ways to improve my coding skills.

Can anyone help me figure this out thanks.

How does function colsure works with recursion in javascript?

Hi I’m new to and still learning JavaScript.

Basically I already have experience in coding using languages like C, C++, and Java.

So I was reading this book called Eloquent JavaScript: A Modern Introduction to Programming and at the page 47 I encounter this thing called closure.

In the book the definition given to closure is;

“Colsure – being able to reference a specific instance of a local binding in an enclosed scope– is called a closure. A function that references bindings from local scopes around it is called a closure


So this is the first example about closure that the book has, for this one I have no trouble in understanding it. (I think…)

function wrapValue(n){
  let local = n;
  return () => local;
}

let wrap1 = wrapValue(1);
let wrap2 = wrapValue(2);

console.log(wrap1());
console.log(wrap2());

If my understanding is correct the function wrapValue returns another function declared locally then binds it to the wrapN variables.


In the second example is where I got confused and I can’t wrap my head around it.

For this one it seems to me that a recursion is involved:

function multiplier(factor){
  return number => number * factor;
}

let twice = multiplier(2);
console.log(twice(5));

How does this thing work?

So we declared a local function called number locally inside the multiplier function’s scope.

Then called it again inside it’s own declaration?

wouldn’t that be an infinite recursion? (but it’s not, it displays 10, but how?)