Skip to main content

Posts

How can I Loop through Array Items and Change Value every time Button is clicked

How can I run through array items and Loop through every single time whenever I clicked the button and change the value based on the array Items that is inside the array. <img src="/assets/a-puppy-1642002.jpg" alt="Random Pictures" id="images"> <div> <button id="img-changer">Random</button> </div> document.getElementById('img-changer').addEventListener('click', (btn) =>{ let src = "src"; let srcpath = "/assets/" let imgstock = [ 'Birds in Flowers Romantic Seamless Pattern Vector Background.jpg', 'bucegi-mountains-1641852.jpg', 'cat-and-kittens-1641561.jpg', 'happy-doggy-1642001.jpg', 'landscape-waterfall-1641818.jpg', 'new-dawn-1641926.jpg', 'river-of-the-world-1642010.jpg', 'annie-at-home-1641997.jpg', 'a-puppy-164200

Client side js wont work with express handlebars

This is my template <html lang="en"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>My Awesome App</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" /> <link rel="stylesheet" type="text/css" href="/.css" /> <script src="/views/layouts/client.js"></script> <script src="/server.js"></script> </head> <body> } </body> </html> I link the file in the head and then I call the function here <input id="months" type="number" min="1" max="300" value="1" step="1" onc

Instantiating an object with boolean false gives unexpected result [closed]

Why does the following code return 'the value of bool1 is incorrect': class NoDefaultParams { constructor(num1, num2, num3, string1, bool1) { this.num1 = num1; this.num2 = num2; this.num3 = num3; this.string1 = string1; this.bool1 = bool1; } calculate() { if (this.bool1) { console.log(this.string1, this.num1 + this.num2 + this.num3); return; } return 'The value of bool1 is incorrect'; } } var fail = new NoDefaultParams(1, 2, 3, "test", false); console.log(fail.calculate()); And why does the following code return the calculate() method: class NoDefaultParams { constructor(num1, num2, num3, string1, bool1) { this.num1 = num1; this.num2 = num2; this.num3 = num3; this.string1 = string1; this.bool1 = bool1; } calculate() { if (this.bool1) { console.log(this.string1, this.num1 + this.num2 + this.num3); return; } return 'The value of bool1 is incorrect

typescript / .Net Core : downloaded jpg/png file format not supported

I'm having difficulty viewing downloaded png/jpg files, the file downloads properly but cannot be viewed. I think it could be related to the way I'm saving the object in typescript or something to do with content header types? Backend: .Net Core 6.0 Web API Frontend: Vue 3 This is the result of trying to open the downloaded image: Fiddler trace shows the image being sent from the server: This is how I'm downloading the file in TS: await someService .download(item.url, item.name) .then(async (r: any) => { const blob = new Blob([r.data]); const link = document.createElement("a"); link.href = URL.createObjectURL(blob); const disposition = r.request.getResponseHeader("Content-Disposition"); if (disposition && disposition.indexOf("attachment") !== -1) { const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/; let matches = filenameRegex.exec(disposition); if (matches != null && matches[

finding specific values in text file python

I have a text file that looks like the one above. How do I get python to read the file such that I only obtain the values for 'gps_alt' 'lat' and 'lon'? source https://stackoverflow.com/questions/74524419/finding-specific-values-in-text-file-python

Understanding NumPy split function to extract sub-grid

So I was given a worksheet exercise as follows: Given the following grid of 25 values, extract the central 3 x 3 sub-grid of 9 s from the larger grid using the split() function: 1 2 3 4 5 1 9 9 9 5 1 9 9 9 5 1 9 9 9 5 1 2 3 4 5 And the solution is as follows: x = np.array([[1,2,3,4,5], [1, 9, 9, 9, 5], [1, 9, 9, 9, 5], [1, 9, 9, 9, 5], [1, 2, 3, 4, 5]]) x1, x2, x3 = np.split(x, [1, 4]) y1, y2, y3 = np.split(x2, [1, 4], axis = 1) print(y2) My question is, why is it [1, 4] in the brackets? does this refer to the element number, if so, should it not be [1, 3]? Sorry if this seems like a very simple question - am still super new to coding!! Thanks in advance :) source https://stackoverflow.com/questions/74524188/understanding-numpy-split-function-to-extract-sub-grid