Here is my code:
let num = 0.0134;
console.log(num.toString().split('').splice(3).splice(1, 0, '.'))
The console.log returns an empty array.
I want it to return ‘1.34’. What am I doing wrong?
Blancer.com Tutorials and projects
Freelance Projects, Design and Programming Tutorials
Category Added in a WPeMatico Campaign
Here is my code:
let num = 0.0134;
console.log(num.toString().split('').splice(3).splice(1, 0, '.'))
The console.log returns an empty array.
I want it to return ‘1.34’. What am I doing wrong?
I’m trying to use this package (or any method) https://www.npmjs.com/package/input-event to read key events using Node.
I use this example code:
const InputEvent = require('input-event');
const input = new InputEvent('/dev/input/event0');
const keyboard = new InputEvent.Keyboard(input);
keyboard.on('keyup' , console.log);
keyboard.on('keydown' , console.log);
keyboard.on('keypress', console.log);
But I see no output.
I am using react-query to make a GET request to my API in which the response is an array of objects. Each object has 1 property which is the name that I want to access. When I log the response to the console, it appears like the image listed at the bottom. However, when I try to access an element of the response, it says “cannot read properties of undefined”.
Here is the code which displays the data as shown in the image:
const { isLoading, error, data } = useQuery('cat_names', () =>
fetch('<api-link>').then(res =>
res.json()
)
)
console.log(data)
Here is the code I used to try accessing the first element of the array.
const { isLoading, error, data } = useQuery('cat_names', () =>
fetch('<api-link>').then(res =>
res.json()
)
)
console.log(data[0])
I have also tried mapping data, with no luck:
const mapped_data = data.map(element => element.name)
console.log(mapped_data)
I am working on a project but I was stumped to see this piece of code
if ((array.length – 1 – i) % 2 === 1) I am just curious as to how it works?
const valid1 = [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8];
const validateCred = (array) => {
let total = 0;
for (var i = array.length - 1; i >= 0; i--) {
// console.log(array[i])
if ((array.length - 1 - i) % 2 === 1) { /*I would like to know what does this do when put in a if statment array.length - 1 - i */
array[i] *= 2;
// console.log(array[i])
if (array[i] > 9) {
array[i] -= 9;
}
}
total += array[i]
console.log(total)
}
return total % 10 === 0;
};
console.log(validateCred(valid1))
I am new to JavaScript, not sure if this very basic question. I’ve created a Bitcoin Price update dashboard using the data fetched from the external WebSocket. I managed to get the data from the WebSocket and display it on the console tab and display the data in a h1 tag. The price updates every seconds. Now i need to show the price in a html field. i tried but it’s kinda hard for me.
I have provided the code snippets below as well as external Websocket from where I am pulling the data.
Please let me know how should I insert the row dynamically into a HTML input field. Thank you so much in advance
<input type="text" class="form-control" id="btcpricenow" readonly>
<script>
var priceSocket = new WebSocket("wss://stream.binance.com:9443/ws/btcusdt@trade"),
liveprice = document.getElementById("btcpricenow");
priceSocket.onmessage = function (event) {
var liveprice = JSON.parse(event.data);
liveprice.innerText = parseFloat(liveprice.p).toFixed(2);
}
</script>
I’m trying to learn and scrape CSS selectors in Puppetter. There is a simple table and I want to fetch all of prices with DOM. When I try document.querySelectorAll("span")
on the console,
it selects all of span tag.I need only prices, and I want to select first two h3 tags which includes 1 and 2 in Number column.
Here is a simple table for my question.
<html
<body>
<div class="example">
<table class="table" border="1" cellpadding="10">
<thead>
<td>Number</td>
<td>Content</td>
<td>Price</td>
<td>Piece</td>
</thead>
<tbody>
<tr data-type="data">
<td class="price"><h3>1</h3></td>
<td>4 Point</td>
<td><span style="font-size: 16px;font-weight: 600;"> 14$</span></td>
<td>1</td>
</tr>
<tr data-type="data">
<td><h3>2</h3></td>
<td>5 Point</td>
<td><span style="font-size: 16px;font-weight: 600;">15$</span></td>
<td>1</td>
</tr>
<tr data-type="data">
<td><h3>3</h3></td>
<td>6 Point</td>
<td><span style="font-size: 16px;font-weight: 600;">16$</td></span>
<td>1</td>
</tr>
<tfoot>
<tr>
<td style='text-align:center' colspan="4"> <span style="font-size: 16px;">Footer</span></td>
</tr>
</tfoot>
</tbody>
</table>
</div>
</body>
</html>
Debugger attached.
Waiting for the debugger to disconnect...
internal/modules/cjs/loader.js:905
throw err;
^
Error: Cannot find module 'node:events'
I am using discord.js and node.js on Visual Studio Code
I’m trying to make a simple discord bot. How can I make it so it checks for a word inside a message? For example if somebody says “i love bananas” and the trigger word is banana, the bot responds with “same”. All I could figure out is how to make it reply to a specific message (like only “banana”), how do I make something like the example I made?
I’ve got json like below, stored in mongodb:
{
createdAt: 1641840199,
name: 'hello'
projects: [ new ObjectId("61dc99b2fdfbd72f33d4d699") ]
}
in projects
array i’ve got an reference to the documents with project. And now i’ve got a question, how to return an array of this objects (full objects, not only it reference id).
PS. I’m using mongodb
library, i do not like moongose
.
Thanks for any help!
We have an web app (not a SPA but headed that direction) which uses 2 technologies: Razor (MVC) and Angular (Razor pages are being rewritten in angular over the next year so it has to be this way due to a lack of resources for a full migration).
Currently the angular pages are hosted in a separate web app (but under the same sub domain), so when MI1-MI3 are clicked, a new tab is launched which loads the corresponding angular page. The same is true when navigating back to the Razor page.
This means, that the Side and Nav(title bar) are duplicated within both applications and styled accordingly to give the appearance of being in the same app.
I inherited this code and don’t like this design as it breaks the experience for the user and leads to code duplication (the side bar menu items have some permission logic)
What I’d like to do is:
I’m considering a couple different approaches and would appreciate some feedback/guidance here:
Any suggestions here? I’m looking for feasibility here especially with the iframe/new-suggestion idea.
Also, I’d like to merge the code bases to have them all built and deployed as a single web app – possible? I believe having an Angular folder within the MVC project would suffice? Caveats?
Here ,I am making an array of objects data2[] and iterating over this array sending each of its objects , I got 1 response in the postman when I checked it , but not others because of this error .
const express = require("express")
const getOrganicData = require('../GoogleSearchScraping/organicData')
const url = require('url');
const router = new express.Router()
router.get('/searchExtended' , async (req, res) =>
{
try {
const queryObject = url.parse(req.url , true).query
console.log("Query is "+queryObject.query);
const data = await getOrganicData(queryObject.query)
const organicData = data[0]
const snippet = data[1]
const htmlSnippet = data[2]
const data2 = new Array(data[0].length)
for (let i = 0; i < data2.length; i++)
{
data2[i] =
{
organicData: organicData[i],
snippet: snippet[i],
htmlSnippet: htmlSnippet[i],
Rank: ""+(i+1)+""
}
}
for (let i = 0; i < data2.length; i++)
{
res.status(201).send(Object.values(data2[i]))
}
}
catch (error) {
res.status(400).send('Error '+error)
}
})
module.exports = router ;
hey guys i think this should be the most in demand programming skill and must be learnt in my opinion but let me hear yours https://shrinke.me/4gsKf
I have value inside callback function and couldn’t return successfully.
async pos(convertedCodeDBSearch) {
var dd;
const x = await idealPostcodes.lookupAddress(convertedCodeDBSearch, function (error, searchResults) {
return searchResults.result.hits[1];
});
console.log('x', x);
}
I need to return searchResults.result.hits[1];
from function.
Here is the code,
Thank you.
—————————————-CODE—————————————
const { MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed } = require("discord.js")
const config = require("../../botconfig/main")
module.exports = {
name: "help",
run: async (client, message, args) => {
const row = new MessageActionRow()
.addComponents(
new MessageSelectMenu()
.setCustomId('select')
.setPlaceholder('Nothing selected')
.addOptions([
{
label: 'Main Menu',
description: 'Shows the main menu',
emoji: "909758706290417714",
value: '0',
},
{
label: 'Config Commands',
description: 'Shows all the config commands',
emoji: "888347974944571392",
value: '1',
},
{
label: 'Economy Commands',
description: 'Shows all the economy commands',
emoji: "910512217168941126",
value: '2',
},
{
label: 'Fun Commands',
description: 'Shows all the fun commands',
emoji: "920258063703879700",
value: '3',
},
{
label: 'Games Commands',
description: 'Shows all the game commands',
emoji: "922464211240632330",
value: '4',
},
{
label: 'Information Commands',
description: 'Shows all the information commands',
emoji: "911535908518527018",
value: '5',
},
{
label: 'Moderation Commands',
description: 'Shows all the moderation commands',
emoji: "908346330412355605",
value: '6',
},
{
label: 'Utility Commands',
description: 'Shows all the utility commands',
emoji: "922461948535271425",
value: '7',
},
{
label: 'Level Commands',
description: 'Shows all commandsrelating to level and xp stuff.',
emoji: "925024469720915990",
value: '8',
},
{
label: 'Owner Commands',
description: 'This is for the BOT OWNER only',
emoji: "925024469720915990",
value: '9',
},
]),
);
const row2 = new MessageActionRow()
.addComponents(
new MessageButton()
.setLabel("Upvote me!")
.setStyle("LINK")
.setEmoji("859253758903320616")
.setURL("https://dblist.ddns.net/bots/like/879000376274219048"),
new MessageButton()
.setLabel("Invite me")
.setStyle("LINK")
.setEmoji("924283654908313600")
.setURL("https://discord.com/oauth2/authorize?client_id=879000376274219048&scope=bot&permissions=2684354568"),
new MessageButton()
.setLabel("Join Support Server")
.setStyle("LINK")
.setEmoji("866779952162799626")
.setURL("https://discord.gg/5hphccNxTD"),
)
const embed = new MessageEmbed()
.setTitle("**HELP MENU**")
.setDescription(`Pls select a category to see more commands.nn> <:57291theqts:925020896840806460> `Prefix`: ${config.prefix}n> <:67322theqts:925020897587396638> `Total Commands`: ${client.commands.size}n> <:84733theqts:925020897813885019> `Total Servers`: ${client.guilds.cache.size}nn For info on bot commands use `.cmd <command>`n To report bugs, use `/report`nTo make suggestions, use `/suggest``)
.setImage("https://cdn.discordapp.com/attachments/925026772544782366/925064779289227324/b68f7d0b-903b-42cc-9770-f37e49941bdd-preview.png")
.setColor("#f4c2c2")
message.reply({ embeds: , components: [row, row2] })
let embed1 = new MessageEmbed()
.setColor('#FFFFFF')
.setTitle('**HELP MENU**')
.addFields(
{ name: "**CONFIG COMMANDS**", value: "`setchatchannel`,`setautorole`, `set-countingchannel`, `setwelcomechannel`, `setleavechannel`" })
.setImage("https://cdn.discordapp.com/attachments/926113119305105409/926199784153432094/standard_11.gif")
.setColor("#f4c2c2")
.setFooter('Page 1')
let embed2 = new MessageEmbed()
.setTitle('**Help Menu**')
.setColor('#FFFFFF')
.addFields(
{ name: "**ECONOMY COMMANDS**", value: "`balance`, `deposit`, `withdraw`, `search`, `shop`, `inv`, `pet`, `adopt`, `buy`, `sell`, `use`, `gamble`, `multi`, `beg`, `daily`, `fish`, `hunt`, `rob`, `rich` `postmeme`" })
.setColor("#f4c2c2")
.setImage("https://cdn.discordapp.com/attachments/926113119305105409/926199784153432094/standard_11.gif")
.setFooter('Page 2')
let embed3 = new MessageEmbed()
.setTitle('**Help Menu**')
.setColor('#FFFFFF')
.addFields(
{ name: "**FUN COMMANDS**", value: "`8ball`, `activity`, `pixelize`, `meme`, `changemymind`,`clyde`, `slap`, `nitro`, `wasted`, `say`, `quote`, `punch`, `owo`, `lovecalc`, `smug`, `eject`, `emojify`" })
.setColor("#f4c2c2")
.setImage("https://cdn.discordapp.com/attachments/926113119305105409/926199784153432094/standard_11.gif")
.setFooter('Page 3')
let embed4 = new MessageEmbed()
.setTitle('**Help Menu**')
.setColor('#FFFFFF')
.addFields(
{ name: "**GAMES COMMANDS**", value: "`c4`, `tictactoe`, `roadrace`, `snake`, `football`, `quickclick`, `catchthefish`, `akinator`, `trivia`, " })
.setImage("https://cdn.discordapp.com/attachments/926113119305105409/926199784153432094/standard_11.gif")
.setColor("#f4c2c2")
.setFooter('Page 4')
let embed5 = new MessageEmbed()
.setTitle('**Help Menu**')
.setColor('#FFFFFF')
.addFields(
{ name: "**INFO COMMANDS**", value: "`help`, `cmd`, `botinfo`, `ping`, `invite`, `embed`, `ticket-panel`" })
.setImage("https://cdn.discordapp.com/attachments/926113119305105409/926199784153432094/standard_11.gif")
.setColor("#f4c2c2")
.setFooter('Page 5')
let embed6 = new MessageEmbed()
.setTitle('**Help Menu**')
.setColor('#FFFFFF')
.addFields(
{ name: "**MOD COMMANDS**", value: "`ban`, `addroleall`, `removeroleall`, `softban`, `purge`, `mute`, `kick`, `tempmute`, `nuke` `stealemoji`, `resetwarns`, `warnings`, `warn`, `rmvwarn`,`addrole`, `removerole`" })
.setFooter('Page 6')
.setImage("https://cdn.discordapp.com/attachments/926113119305105409/926199784153432094/standard_11.gif")
.setColor("#f4c2c2")
let embed7 = new MessageEmbed()
.setTitle('**Help Menu**')
.setColor('#FFFFFF')
.addFields({ name: "**UTILITY COMMANDS**", value: "`addtag`, `edittag`, `removetag`, `afk`, `rolelist`, `snipe`, `timer`, `calculator`, `avatar`, `serverinfo`, `ss`, `dump`" })
.setImage("https://cdn.discordapp.com/attachments/926113119305105409/926199784153432094/standard_11.gif")
.setColor("#f4c2c2")
.setFooter('Page 7')
let embed8 = new MessageEmbed()
.setTitle('**Help Menu**')
.setColor('#FFFFFF')
.addFields({ name: "**LEVEL COMMANDS**", value: "`rank`, `leaderboard`, `addrole`, `removerole`, `listroles`" })
.setImage("https://cdn.discordapp.com/attachments/925037840977526896/925057005335511101/b68f7d0b-903b-42cc-9770-f37e49941bdd-preview.png")
.setColor("#f4c2c2")
.setFooter('Page 8')
let embed9 = new MessageEmbed()
.setTitle('**Help Menu**')
.setColor('#FFFFFF')
.addFields({ name: "**OWNER COMMANDS**", value: "`addpremium`, `eval`, `reload`, `remove-premium`, `slt`, `terminal` " })
.addFields({ name: "**OWNER ECONOMY COMMANDS**", value: "`addcoins`, `addbank`, `rmvcoins`, `rmvbank`, `resetcoins`, `resetbank`, `deluser`" })
.setImage("https://cdn.discordapp.com/attachments/925037840977526896/925057005335511101/b68f7d0b-903b-42cc-9770-f37e49941bdd-preview.png")
.setColor("#f4c2c2")
.setFooter('Page 9')
const filter = i => i.user.id === message.author.id;
const collector = message.channel.createMessageComponentCollector({
filter,
time: 40000,
componentType: "SELECT_MENU"
});
collector.on("collect", async (collected) => {
const value = collected.values[0]
if (value === "0") {
collected.edit({ embeds: , components: [row, row2] })
}
if (value === "1") {
collected.edit({ embeds: [embed1], components: [row, row2] })
}
if (value === "2") {
collected.edit({ embeds: [embed2], components: [row, row2] })
}
if (value === "3") {
collected.edit({ embeds: [embed3], components: [row, row2] })
}
if (value === "4") {
collected.edit({ embeds: [embed4], components: [row, row2] })
}
if (value === "5") {
collected.edit({ embeds: [embed5], components: [row, row2] })
}
if (value === "6") {
collected.edit({ embeds: [embed6], components: [row, row2] })
}
if (value === "7") {
collected.edit({ embeds: [embed7], components: [row, row2] })
}
if (value === "8") {
collected.edit({ embeds: [embed8], components: [row, row2] })
}
if (value === "9") {
collected.edit({ embeds: [embed9], components: [row, row2] })
}
})
}
}
—————————————-NOTE—————————————
So this is my help command code. When i run the command it replies but doesnt update menu when i choose a menu it rather sends an error code in console saying DiscordAPIError: Unknown interaction
. Ive tried lots of ways to fix this but none worked. Please help
I have a class constructor with a nested object structure. Each level has a property x
.
this.x > this.a.x > this.a.b.x
I want this.a.b.x
to point to the value of this.a.x
, but it instead points to this.x
.
class Example {
constructor() {
this.x = 0;
this.a = {
x: this.x + 5,
b: {
x: this.x // I want this to equal 5
}
}
}
}
const ex = new Example();
console.log(ex.x) // 0
console.log(ex.a.x) // 5
console.log(ex.a.b.x) // 0 <-- I want this to be 5
How can I change the this
reference in this.a.b
to point to this.a
rather than this?
?