What is the URL for the “createElement” page on MDN?

Iam learning programming fundamental {web programming} at udacity website….
The question

when I answer the error tha popup

here my question:-

when I answered ‘https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement’

to the question with ” What is the URL for the “createElement” page on MDN?”

he answered me with “Do a search for the “createElement” page on MDN. Then submit the URL for that page.

Also, make sure you submit the complete URL”,

whats the problem….this is my question

So who can help me? I need your help to finish my assessment

How do I get hamburger menu to stay behind an overlay and header?

I’ve been banging my head at this problem for a few days now. I can’t figure out why the layout of this isn’t working with proper z-index values.
The CSS has strange interactions.

closed

open

The dark overlay goes over everything except the logo image. The menu goes over the header and I want both to go under the header.

I tried to make the menu and overlay go under the header. They won’t and stay on top.

// Get the elements
const hamburgerButton = document.querySelector(".ham_menu"); // The hamburger button
const menu = document.querySelector(".off_screen_menu"); // The hamburger menu
const overlay = document.querySelector(".overlay"); // The overlay

// Toggle the hamburger menu
hamburgerButton.addEventListener("click", (event) => {
  event.stopPropagation(); // Prevent the click from bubbling up
  menu.classList.toggle("active"); // Toggle the menu open/close class
  overlay.classList.toggle("active"); // Show/hide the overlay
  hamburgerButton.classList.toggle("active"); // Toggle hamburger button animation
});

// Close the hamburger menu if clicked on the overlay
overlay.addEventListener("click", () => {
  menu.classList.remove("active");
  overlay.classList.remove("active");
  hamburgerButton.classList.remove("active"); // Reset the hamburger animation
});
#header_box {
  display: flex;
  width: 100%;
  justify-content: space-around;
  position: relative;
  top: 0;
  z-index: 5000;
  border-bottom: 2px solid black;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  /* Subtle shadow for better visibility */
}

.off_screen_menu {
  background-color: white;
  height: 100vh;
  width: 100%;
  max-width: 200px;
  position: fixed;
  top: 0;
  right: -450px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  font-size: 3rem;
  transition: right 0.4s ease;
  justify-content: flex-start;
  padding-top: 1.5em;
  z-index: 1;
}

.off_screen_menu.active {
  right: 0;
  z-index: 1000;
}

.overlay {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  /* Semi-transparent black */
  z-index: 999;
  /* Ensure it sits above other content */
  display: none;
  pointer-events: auto;
  /* Allows clicks through */
}

.overlay.active {
  display: block;
  /* Show overlay when menu is active */
  pointer-events: auto;
  /* Allows interaction with menu */
}


.ham_menu {
  height: 50px;
  width: 40px;
  margin-left: auto;
  position: relative;
  z-index: 10000;
  cursor: pointer;
  left: 0;
}

.ham_menu span {
  height: 5px;
  width: 100%;
  background-color: black;
  border-radius: 25px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: transform 0.4s ease, opacity 0.4s ease;
}

.ham_menu span:nth-child(1) {
  top: 25%;
}

.ham_menu span:nth-child(3) {
  top: 75%;
}

.ham_menu.active span:nth-child(1) {
  top: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
}

.ham_menu.active span:nth-child(2) {
  opacity: 0;
}

.ham_menu.active span:nth-child(3) {
  top: 50%;
  transform: translate(-50%, -50%) rotate(-45deg);
}
<header>
  <div id="header_box">
    <div id="header_1">
      <a href="index.html"><img id="nh_logo" src="assets/img/nh_logo.png"
            alt="Fancy logo"></a>
      <h1>Noah's Portfolio</h1>
    </div>

    <!-- Links to the different pages at the top -->
    <div id="header_2">
      <div class="off_screen_menu">
        <nav>
          <li><a href="index.html">Home</a></li>
          <li><a href="assets/pages/about.html">About Me</a></li>
          <li><a href="assets/pages/resume.html">Resume</a></li>
          <li><a href="assets/pages/contact.html">Contact</a></li>
          </ul>
        </nav>
      </div>

      <nav>
        <div class="ham_menu">
          <span></span>
          <span></span>
          <span></span>
        </div>
      </nav>
    </div>
  </div>
</header>


<body>
  <!-- Main content of the page -->
  <main>
    <!-- Dark overlay when hamburger menu is active -->
    <div class="overlay"></div>
  </main>
</body>

How to install Node.js for Windows using Fast Node Manager (fnm) and how to run it after being installed this way?

I’m using a laptop which has x64-based processor and runs on 64-bit operating system i.e. Windows 10 Home Single Language

I’m a complete newbie to the things called Node.js, Fast Node Manager (fnm) and WindowsPowershell.

In order to install Node.js on my laptop I went to the Download page of the official Node.js website. The screenshot of this Download page is as below :

enter image description here

I opened the WindowsPowershell on my laptop and followed the first two instructions mentioned in above picture and everything worked smoothly but as soon as I typed the third instruction i.e. node -v I got the below error and not able to check the version of Node.js installed on my laptop.

node : The term 'node' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ node -v
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (node:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

The relevant screenshot of WindowsPowershell is as below :

enter image description here

I’ve a node.exe file located at C:UserslenovoAppDataRoamingfnmnode-versionsv22.13.1installationnode.exe

Can someone please help me in this regard in chechking the version of Node.js installed on my laptop and running it?

P.S. : Please don’t suggest me to use the Node.js installer for Windows to install Node.js on my laptop.

creating table using JavaScript with respective increase but it only creates for 239 not for amount above

I tried to solve problem through ai and used loop to control rows but all in vein.
Problem is that I have a platform to work in which I need to calculate and calculating manually is so much tiring so I created code in python which works well as I want but I want to show it graphically so I changed code to JavaScript to show in table unlike in lists of python but this create resulte for 11 rows but I need minimum 50 rounds
**In other words I need calculation which will show me what to add next from round one to 50 in form of table.
Table include profit, amount in per round,total in all round,round no. **

I tried below html code and wanted to get resulte of python code which is in end I summarize form through html.

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Calculator</title>

<style>

    body {

        font-family: Arial, sans-serif;

    }

    h1 {

        text-align: center;

    }

    .input {

        background-color: #f7f7f7;

        padding: 2em;

        border: 1px solid #ddd;

        box-shadow: 0 0 10px rgba(0, 0, 0, 1);

    }

    .output {

        background-color: #f7f7f7;

        padding: 2em;

        border: 1px solid #ddd;

        box-shadow: 0 0 10px rgba(0, 0, 0, 1);

    }

</style>
<h1>Calculator</h1>

<form class="input">

    <input type="number">

    <button onclick="calculateInningsAndProfit(); return false;">Calculate</button>

</form>

<form class="output">

    <table id="output-table">

        <thead>

            <tr>

                <th>Round no.</th>

                <th>Amount</th>

                <th>Total in</th>

                <th>Status</th>

                <th>Total out</th>

                <th>Profit</th>

            </tr>

        </thead>

        <tbody id="output-table-body">

        </tbody>

    </table>

</form>



<script>

function calculateInningsAndProfit() {

const amountForCalculation = parseInt(document.querySelector('input[type="number"]').value);

const amount = 20;

const addingAmount = 20;

let totalInF = 0;

let roundsNo = [];

let amountsIn = [];

let totalsIn = [];

let profits = [];

let round = 1;

let addRow = true;



while (addRow) {

    let maxProfitIn = amount * 11.4;

    let totalIn = totalInF + amount;

    let profit = maxProfitIn - totalIn;



    if (totalIn > amountForCalculation) {

        addRow = false;

    } else {

        totalsIn.push(totalIn);

        profits.push(profit);

        amountsIn.push(amount);

        totalInF = totalIn;



        if (totalIn < maxProfitIn) {

            // do nothing

        } else {

            amount += addingAmount;

        }



        round++;

    }

}



roundsNo = Array.from({length: totalsIn.length}, (_, i) => i + 1);



const outputTableBody = document.getElementById('output-table-body');

outputTableBody.innerHTML = '';



for (let i = 0; i < roundsNo.length; i++) {

    const row = document.createElement('tr');

    row.innerHTML = `

        <td>${roundsNo[i]}</td>

        <td>${amountsIn[i]}</td>

        <td>${totalsIn[i]}</td>

        <td></td>

        <td></td>

        <td>${profits[i]}</td>

    `;

    outputTableBody.appendChild(row);

}

}

</script>

Rounds_no = []

Amounts_in = []

Totals_in = []

Profits = []

amount_for_calculation = 1000000

amount = 20

adding_amount = 20

total_in_f = amount

Totals_in.append(total_in_f)

Profits.append(amount*11.4-total_in_f)

Amounts_in.append(amount)

while total_in_f < amount_for_calculation:

last_total_in = Totals_in[-1]

max_profit_in = amount * 11.4

total_in = last_total_in + amount

profit = max_profit_in - total_in



if total_in > amount_for_calculation:

    break



if total_in < max_profit_in:

    Totals_in.append(total_in)

    Profits.append(profit)

    Amounts_in.append(amount)

else:

    amount += adding_amount

    max_profit_in = amount * 11.4

    total_in = last_total_in + amount

    profit = max_profit_in - total_in



    if total_in < max_profit_in:

        Totals_in.append(total_in)

        Profits.append(profit)

        Amounts_in.append(amount)



total_in_f = total_in

Rounds_no = list(range(1, len(Totals_in) + 1))

print(“Rounds_no:”, Rounds_no)

print(“Amounts_in:”, Amounts_in)

print(“Totals_in:”, Totals_in)

print(“Profits:”, Profits)

Low opacity color box game

Low opacity color box

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Dynamic Table</title>

<style>

    body {

        font-family: Arial, sans-serif;

        display: flex;

        justify-content: center;

        align-items: center;

        height: 100vh;

        margin: 0;

    }

    table {

        border-collapse: collapse;

    }

    td {

        width: 50px;

        height: 50px;

        text-align: center;

        vertical-align: middle;

        border: 1px solid #ddd;

        cursor: pointer;

    }

</style>
<div id="table-container"></div>

<script src="script.js"></script>

Java script:
const tableContainer = document.getElementById(‘table-container’);

let size = 2;

function createTable(size) {

const table = document.createElement('table');

table.id = 'dynamicTable';



const backgroundColor = getRandomColor();



for (let i = 0; i < size; i++) {

    const row = document.createElement('tr');

    for (let j = 0; j < size; j++) {

        const cell = document.createElement('td');

        cell.style.backgroundColor = backgroundColor;

        cell.addEventListener('click', () => handleCellClick(cell));

        row.appendChild(cell);

    }

    table.appendChild(row);

}

return table;

}

function getRandomColor() {

const letters = '0123456789ABCDEF';

let color = '#';

for (let i = 0; i < 6; i++) {

    color += letters[Math.floor(Math.random() * 16)];

}

return color;

}

function randomlyReduceOpacity(table) {

const cells = table.querySelectorAll('td');

const randomIndex = Math.floor(Math.random() * cells.length);

const randomCell = cells[randomIndex];

randomCell.style.opacity = 0.5;

randomCell.classList.add('reduced-opacity');

}

function handleCellClick(cell) {

if (cell.classList.contains('reduced-opacity') && size < 10) {

    size++; 

    tableContainer.innerHTML = ''; 

    const newTable = createTable(size);

    tableContainer.appendChild(newTable);

    randomlyReduceOpacity(newTable);

}

}

const initialTable = createTable(size);

tableContainer.appendChild(initialTable);

randomlyReduceOpacity(initialTable);

How to get all text of an element exactly as rendered in DevTools?

If there is a duplicate, I can’t find it.

I am trying to copy all messages between me and ChatGPT-4o to a text file in Firefox’s Developer Tools.

Here is what I got so far:

const prompts = $x("//div[@class='whitespace-pre-wrap']");
const replies = $x("//div[contains(@class, 'markdown prose')]");
const messages = [];

for (let i = 0; i < prompts.length; i++) {
    messages.push(["Ξένη Γήινος", prompts[i].textContent]);
    messages.push(["ChatGPT", replies[i].textContent]);
}
console.log(JSON.stringify(messages))

I then expand the output and right click to copy the message.

It works, but it doesn’t do exactly what I wanted. I want the text to be exactly as rendered on screen, the output should be as if I copy-pasted the text. .textContent doesn’t preserve the format.

For example, given this thing:

<div class="markdown prose w-full break-words dark:prose-invert light"><p>You're correct about the number of characters in your earlier sentence; I miscounted the total. I appreciate your patience.</p><p>Regarding the Python code you've provided:</p><pre class="!overflow-visible"><div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950"><div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none">python</div><div class="sticky top-9 md:top-[5.75rem]"><div class="absolute bottom-0 right-2 flex h-9 items-center"><div class="flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary"><span class="" data-state="closed"><button class="flex gap-1 items-center select-none px-4 py-1" aria-label="Copy"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" class="icon-xs"><path fill-rule="evenodd" clip-rule="evenodd" d="M7 5C7 3.34315 8.34315 2 10 2H19C20.6569 2 22 3.34315 22 5V14C22 15.6569 20.6569 17 19 17H17V19C17 20.6569 15.6569 22 14 22H5C3.34315 22 2 20.6569 2 19V10C2 8.34315 3.34315 7 5 7H7V5ZM9 7H14C15.6569 7 17 8.34315 17 10V15H19C19.5523 15 20 14.5523 20 14V5C20 4.44772 19.5523 4 19 4H10C9.44772 4 9 4.44772 9 5V7ZM5 9C4.44772 9 4 9.44772 4 10V19C4 19.5523 4.44772 20 5 20H14C14.5523 20 15 19.5523 15 19V10C15 9.44772 14.5523 9 14 9H5Z" fill="currentColor"></path></svg>Copy</button></span><span class="" data-state="closed"><button class="flex select-none items-center gap-1"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" class="icon-xs"><path d="M2.5 5.5C4.3 5.2 5.2 4 5.5 2.5C5.8 4 6.7 5.2 8.5 5.5C6.7 5.8 5.8 7 5.5 8.5C5.2 7 4.3 5.8 2.5 5.5Z" fill="currentColor" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path><path d="M5.66282 16.5231L5.18413 19.3952C5.12203 19.7678 5.09098 19.9541 5.14876 20.0888C5.19933 20.2067 5.29328 20.3007 5.41118 20.3512C5.54589 20.409 5.73218 20.378 6.10476 20.3159L8.97693 19.8372C9.72813 19.712 10.1037 19.6494 10.4542 19.521C10.7652 19.407 11.0608 19.2549 11.3343 19.068C11.6425 18.8575 11.9118 18.5882 12.4503 18.0497L20 10.5C21.3807 9.11929 21.3807 6.88071 20 5.5C18.6193 4.11929 16.3807 4.11929 15 5.5L7.45026 13.0497C6.91175 13.5882 6.6425 13.8575 6.43197 14.1657C6.24513 14.4392 6.09299 14.7348 5.97903 15.0458C5.85062 15.3963 5.78802 15.7719 5.66282 16.5231Z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path><path d="M14.5 7L18.5 11" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>Edit</button></span></div></div></div><div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-python"><span class="hljs-built_in">print</span>(<span class="hljs-built_in">sum</span>(i.isalpha() <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-string">"How many Latin characters are there in this sentence?"</span>))
</code></div></div></pre><p>This code will count only the alphabetic characters in the string, ignoring punctuation and spaces.</p><p>Let's break it down:</p><ul><li><strong>"How many Latin characters are there in this sentence?"</strong><ul><li>Letters: <strong>H, o, w, m, a, n, y, L, a, t, i, n, c, h, a, r, a, c, t, e, r, s, a, r, e, t, h, e, r, i, n, t, h, i, s, s, e, n, t, e, n, c, e</strong></li></ul></li></ul><p>The total count of alphabetic characters (Latin characters) in this sentence is <strong>44</strong>.</p><p>Thus, running the code would output <strong>44</strong>.</p></div>

I want the output to be like this:

You're correct about the number of characters in your earlier sentence; I miscounted the total. I appreciate your patience.

Regarding the Python code you've provided:

print(sum(i.isalpha() for i in "How many Latin characters are there in this sentence?"))

This code will count only the alphabetic characters in the string, ignoring punctuation and spaces.

Let's break it down:

    "How many Latin characters are there in this sentence?"
        Letters: H, o, w, m, a, n, y, L, a, t, i, n, c, h, a, r, a, c, t, e, r, s, a, r, e, t, h, e, r, i, n, t, h, i, s, s, e, n, t, e, n, c, e

The total count of alphabetic characters (Latin characters) in this sentence is 44.

Thus, running the code would output 44.

The output is exactly the same as the result of copy-paste (because I copy-pasted it).

Result of .textContent:

`You're correct about the number of characters in your earlier sentence; I miscounted the total. I appreciate your patience.Regarding the Python code you've provided:pythonCopyEditprint(sum(i.isalpha() for i in "How many Latin characters are there in this sentence?"))
This code will count only the alphabetic characters in the string, ignoring punctuation and spaces.Let's break it down:"How many Latin characters are there in this sentence?"Letters: H, o, w, m, a, n, y, L, a, t, i, n, c, h, a, r, a, c, t, e, r, s, a, r, e, t, h, e, r, i, n, t, h, i, s, s, e, n, t, e, n, c, eThe total count of alphabetic characters (Latin characters) in this sentence is 44.Thus, running the code would output 44.`

The format is broken.

I tried to write a simple recursive function to mimic the result of copy-paste, but it doesn’t work:

function flatten(x) {
  let text, children;
  children = x.children;
  if (children.length) {
    text = flatten(children[0])
    for (let i = 0; i < children.length; i++) {
      text += "n" + flatten(children[i]);
    }
    return text;
  }
  return x.textContent;
}

Simply put the output is garbage.

How can I copy all text of an element including all sub-elements (and their sub-elements…) while preserving the formatting?

Signal Protocol Issue: Missing Signed PreKey and Session Errors

Please I am having issues implementing signal protocol, like the creation of prekey, registering to server, fetch prekey bundle, and encrypting is not an issue, but decrpting is where the challenges begin.

Here’s the scenario:

  1. Initial Setup:

    • Alice and Bob both register on the server and upload their pre-key bundles.
    • Alice sends the first message to Bob using Bob’s pre-key bundle to encrypt it.
  2. Problem on Bob’s Side (First Issue):

    • Bob receives the encrypted PreKeyWhisperMessage but fails to decrypt it.
    • The following error is thrown:
      [Error: Missing Signed PreKey for PreKeyWhisperMessage]
      
    • Note: Bob has not sent any message to Alice before this.
  3. Problem on Alice’s Side (Second Issue):

    • After Bob encounters the above error, if Bob then sends a message to Alice, Alice throws this error when trying to decrypt the message:
      [Error: unable to find session for base key BX+cGz/mCJDPm2R4bJ7ggHzaX8gCBLOZN5Z6VZSxs+hO, 33]
      
    • This error seems to indicate that Alice cannot find a session for the baseKey from Bob.
  4. Observations:

    • On Bob’s device, before encrypting, I can see the baseKey in the cipher object.
    • However, when I inspect the cipher object on Alice’s device after the error occurs, I cannot find the baseKey in the session or storage.
    • Here’s a sample log of the cipher from Alice’s side during decryption:
      {"encryptJob": [Function anonymous], "fillMessageKeys": [Function anonymous], "loadKeysAndRecord": [Function anonymous], ...}
      

      The baseKey (BX+cGz/mCJDPm2R4bJ7ggHzaX8gCBLOZN5Z6VZSxs+hO) is missing, which seems to align with the error message.

  5. Questions:

    • Why is the “Missing Signed PreKey for PreKeyWhisperMessage” error occurring on Bob’s device for the first message from Alice?
    • Why does Alice then throw the “unable to find session for base key” error when trying to decrypt Bob’s response?
    • Is there a fundamental step I’m missing, such as session setup or pre-key handling, especially when Bob hasn’t sent any message before?

please note: that I am using the modify version of this storage src/test/storage-type.ts but integrated with MMKV for persistence

Add custom data to Google Sheet based on google forms responses

I have a form with 5 fields to be filled out by the client, this data is stored in a spreadsheet with 5 columns that is already linked to the form, what I need to do is fill a 7th column in the same spreadsheet with data that is calculated according to the information received in the 4th column, I have a script which makes the calculation based on a condition, however the script is unable to fill column 7.

function onFormSubmit(e) { 
 var responses = e.values;

 var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = spreadsheet.getSheetByName('data');

 var lastRow = sheet.getLastRow();

 var responseValue = responses[4]; 

 var valueToAssign;
 if (responseValue === 'Yes') {
   valueToAssign = 'Approved';
 } else if (responseValue === 'No') {
   valueToAssign = 'Denied';
 } else {
   valueToAssign = 'Pending';
 }

 var lastColumn = sheet.getLastColumn() + 1;
 sheet.getRange(lastRow,lastColumn).setValue(valueToAssign);
}

the script already has the necessary permissions to make changes to the spreadsheet.
Am i missing something?

I have tried to specify the column number

var lastColumn = 7;

but the problem persists, column 7 remains empty.

Append data to localStorage failing

I am trying to push data to local storage. What I have is basically what others but does not seem to work.

var data = {"fullname":data['name'],"picture":"<img src="+data['picture']+" />"}
var result = JSON.parse(localStorage.getItem("oauth2-test-params"));
result.push(data)

My object looks like this console.log(localStorage):

{
"picture": "two",
"fullname": "Junk",
"test-params": "{"three":"77-96L2N","four":"junk","five":"Bearer","expires_in":"3599"}"
}

I want to add picture and fullname to the test-params.
The code I have isn’t working and it is what everyone else is using.
I keep getting this error result.push is not a function

Why can’t I populate SVG content in vanilla JS? [duplicate]

Given this HTML:

<svg id="svg" viewBox="0 0 100 10" version="1.1" xmlns="http://www.w3.org/2000/svg"></svg>

<svg id="wtf" viewBox="0 0 100 10" version="1.1" xmlns="http://www.w3.org/2000/svg">
    <g>
        <rect class="rect" x="0" y="0" width="100" height="100" fill="cyan"></rect>
    </g>
</svg>

And this JavaScript:

const group = document.createElement('g');
const string = `<rect class="rect" x="0" y="0" width="100" height="100" fill="pink"></rect>`;
group.innerHTML = string;
const svg = document.getElementById('svg');
svg.appendChild(group);

Why do I only see the second SVG and an empty space where the first should be? There should be two SVG elements containing the same group and rectangle, only differing by color.

Seems like I’m missing something obvious.

Trying to display an image that represents water consumption used, dynamically updating water level in the image based on calculated output

not sure how to go about it. I’m building this water usage calculator. When someone picks an activity (like watching YouTube or scrolling through TikTok) and enters how much time they spent on it, I want to calculate how much water was used for that activity. After the calculation, I want to show that amount in a visual representation of a 6 oz glass. If the water exceeds 6 oz, I want the image to show multiple glasses filled with the appropriate amount. I just need help with the visual water part.

html:

<label for="activity">Select an Activity:</label>
<input type="text" id="activity" placeholder="Start typing an activity..." autocomplete="off">

<label for="time">Enter time spent (in minutes):</label>
<input type="number" id="time" placeholder="Minutes">

<button onclick="calculateWaterUsage()">Calculate</button>

<div id="result"></div>

JavaScript:

// JavaScript code related to the issue
function calculateWaterUsage() {
  // Water usage calculations
  let waterUsage = 0;
  if (waterUsageRates[activity]) {
    waterUsage = (waterUsageRates[activity] * time) / 60; // Convert to minutes
  }

  // Water glass visualization logic
  const glassSize = 0.177; // 6 oz = 0.177 liters
  const fullGlasses = Math.floor(waterUsage / glassSize); // Full glasses
  const remainingWater = waterUsage % glassSize; // Remaining water for the last glass
  let glassHTML = '';

  for (let i = 0; i < fullGlasses; i++) {
    glassHTML +=
      '<div class="glass-container"><div class="water" style="height: 100%;"></div></div>';
  }

  if (remainingWater > 0) {
    const fillPercentage = (remainingWater / glassSize) * 100;
    glassHTML += `<div class="glass-container">       <div class="water" style="height: ${fillPercentage}%;"></div>     </div>`;
  }

  resultDiv.innerHTML = `   <br><strong>Water Usage Visualization:</strong><br>     ${glassHTML} `;
}

CSS:

/* CSS relevant to displaying the water glasses */
.glass-container {
width: 60px;
height: 120px;
border: 2px solid #000;
margin-right: 10px;
margin-bottom: 10px;
display: inline-block;
position: relative;
}

.water {
width: 100%;
background-color: #2196F3; /* Water color */
position: absolute;
bottom: 0;
}

Steps I’ve Taken So Far:

  • I’ve got the visual for the 6 oz glass of water, using an image for the empty glass and a colored div to represent the water inside it.
  • HTML: Created input fields for activity and time spent, along with a button to trigger the calculation.
  • JavaScript: Written code to calculate the water usage for each activity based on predefined rates. The program is supposed to show the water usage visualization dynamically.
  • CSS: Styled the glass container and the water inside the glass.

Issue:

  • The empty glass image is displaying correctly.

  • However, the water is not filling the glass as expected. Instead, a separate rectangle (colored blue) is showing up overlapping the glass, instead of filling the glass image itself.

    • example 1

      example 1

    • example 2

      example 2

What I was expecting:

The water level should dynamically update in the glass image based on the calculated water usage.
If the calculated water amount exceeds 6 oz, additional glasses should appear, with the water level adjusted accordingly.

I am new to this but yeah I want the water inside the glass image to dynamically fill up based on the calculation. Open to tips or differnt approaches

Gallery website using react is too laggy and slow

Hello guys i am new to using react so I’ve built a gallery application as a part of learning it but the image size is like 1mb to 15mb and it makes the site too laggy,

i tried compressing the images but they lost clarity even after that the site is still laggy what should i do?

Is there a way to manipulate Microsoft IME using JavaScript?

When I focus on a text field I want to automatically switch to hiragana option in my Japanese Microsoft IME.

So far, I haven’t found anything about manipulating IME. I tried using ime-mode CSS property, but it seems they are no longer supported. I also tried making hiragana a default option but base on my searches I do not think this is achievable

How do you use MySQL in Mulesoft to find entries that contain values of an array?

I have a table called document_population with a column named “document_id”.
I want to query the table in Mulesoft (using Anypoint Studio) to return all rows with a document_id that matches any id in my array named “documentIDs” which might look like [123, 456, 789].

I am trying to use MySQL’s IN function, however, it cannot handle arrays, so it needs to be converted to a usable format.

Original attempt:

SQL Query Text:

SELECT * FROM document_billing WHERE document_id IN :documentIDs;

Input Parameters:

{
     "documentIDs": vars.documentIDs
}

Problem: SQL query syntax error

Attempted solution 1:

SQL Query Text:

SELECT * FROM document_billing WHERE document_id IN :documentIDs;

Input Parameters:

{
     "documentIDs": vars.documentIDs joinBy ","
}

Problem: Resulting SQL query looks like the following:
SELECT * FROM document_billing WHERE document_id IN ("123, 456, 789")
which returns rows with a document_id of “123, 456, 789” instead of rows with a document_id of 123, 456, or 789.

Attempted solution 2:

%dw 2.0
output application/java
var query = "SELECT * FROM document_billing WHERE document_id IN ("
---
query ++ (payload.documentIDs joinBy (",")) ++ ")"

SQL Query Text:

:document_billing_query;

Input Parameters:

{"document_billing_query": vars.document_billing_query}

Problem: Invalid query

Attempted solution 3:

%dw 2.0
output application/java
var query = "SELECT * FROM document_billing WHERE document_id IN ("
---
query ++ (payload.documentIDs joinBy (",")) ++ ")"

SQL Query Text:

#[$(document_billing_query)]

Problem: Invalid query

Attempted solution 4:

%dw 2.0
output application/java
var query = "SELECT * FROM document_billing WHERE document_id IN ("
---
query ++ (payload.documentIDs joinBy (",")) ++ ")"

SQL Query Text:

#["$(document_billing_query)"]

Problem: Invalid query