Posts by Andre • 5,836 points
229 posts
-
1
votes1
answer181
viewsA: .find() from Mongoose returns nothing when it should
One of the problems I see is that you want to query using a regular expression, but are using a string as a parameter. In the following code line: const query = model.find({url: {'$in':…
-
0
votes2
answers135
viewsA: Problems with Nan when getting input values
You are caching input values right when initializing the page. var num1 = parseFloat(document.getElementById("n1").value); var num2 = parseFloat(document.getElementById("n2").value); Since this…
javascriptanswered Andre 5,836 -
1
votes3
answers464
viewsA: What is a Guard clause?
Roughly Guards is a mechanism that allows the compiler to infer the state of a variable. Its implementation depends on the language, but a widely used type of guard is to protect the code from…
-
1
votes2
answers131
viewsA: I am training the basics of Javascript and need help in a To-Do List
This way that you implemented your function is not very orthodox, you are declaring the function removerTarefa in the global scope dynamically and then assigning the reference of this function to…
-
1
votes4
answers118
viewsA: How to reference a JS item from a DOM element
The problem with its function is that it is being generated from a string. A string has no way to store a reference to its task array, you would need to store some type of identifier (a number or a…
javascriptanswered Andre 5,836 -
2
votes1
answer94
viewsA: Help with a javascript code (Beginner)
I imagine that if you are submitting this code for some automatic test, this test will call your function several times with different parameters. Like moedas is declared in the global scope, this…
-
5
votes1
answer2281
viewsA: Javascript function - help
From what I understand of the statement, it is not for you to create the function triplo, is for you to consider that it already exists and use it. Assuming this is the triple function: function…
-
3
votes1
answer232
viewsA: How Dart interprets a ()=>{x,y,z} Arrow in lambda/anonymous functions
That’s because in Dart, big arrow function always denotes a return. Unlike Javascript, in Dart, when you open keys after the arrow (=>) of big arrow function, you’re not opening a scope, you’re…
-
1
votes3
answers140
viewsA: How do I place a conditional within a . foreach() in Javascript?
There is no way to use a condition if right after the operator =>. When you declare a arrow function without opening the scope using keys, you need to declare an expression with a return. As if…
-
2
votes1
answer65
viewsA: Fução to find and remove term in the array does not work with variavél!
You need to bring the variable $val_busca within the scope of the function, or else you will not be able to access it: foreach($arr_val as $val_busca){ $frutas = array_filter($frutas, function…
-
0
votes1
answer33
viewsA: How to use attr(Selected) in a dynamically created option?
It seems your problem is in $('option[value=' + item.freteStatusID + ']') In this query you are looking for all elements option with the value item.freteStatusID on your page, not just inside the…
-
1
votes1
answer58
viewsA: How does the Symbol() data type work?
The detail of the log is that it does not have a well defined behavior by Ecmascript, so we see some differences in its behavior in different browsers, such as when you log a HTMLElement in Chrome…
-
0
votes1
answer160
viewsA: Two javascript functions on the same page
You say you have already tried to change the ids and have not worked out, but this is exactly what needs to be done: $(document).ready(function() { $('#login-trigger').click(function() {…
-
4
votes1
answer100
viewsA: Run PHP in an orderly fashion
PHP even prints in order, the problem is that usually your browser will caching the answer, only to show the user the answer after receiving it completely. You can add some headers on the server…
-
3
votes1
answer110
views -
4
votes1
answer92
viewsA: I need to initialize the variable with the value 0, why?
You don’t need to initialize preco with 0, but you need to ensure that this variable will be initialized before you print it on the screen. See that in your code you initialize preco within a…
-
2
votes1
answer36
viewsA: how to make my function return increment?
You are using the wrong destructor. Keys {} are used to unstructure an object, brackets [] server to unstructure an array. The return of function useState is an array with two items, the first item…
-
5
votes1
answer76
viewsA: Correct use of lambda with filter()
filter is a function used to return items from your list that meet the condition, and nothing else. If your goal is to create a list containing only the days of these items that meet the condition,…
-
4
votes1
answer100
viewsA: Async functions inside setInterval giving Syntax Error in HTML
The error is happening because you are not passing a function to the setInterval. setInterval receives two parameters; a function, and the time in milliseconds to perform this function. Now see what…
-
0
votes2
answers48
viewsA: Subtraction between 2 fields
The problem is you’re trying to capture the value of tg and td, which are elements of the <td>, that is to say, HTMLTableCellElement. This class does not have value, note that you use it…
javascriptanswered Andre 5,836 -
2
votes1
answer1327
viewsA: How to convert String to Int in C++
Several errors in this code. Starting with include #include <string.h> #include <stdlib.h> string It doesn’t have the extension .h. This is actually a bit confusing, in C++ the library…
-
0
votes1
answer200
viewsA: Request data is not returning correctly
There are many errors regarding the treatment of asynchronism in this code, so much so that it is even difficult to describe the entire flow of the code to explain how it arrived at this final…
-
0
votes1
answer25
viewsA: Create if Findoneupdate does not find anything
Information is missing in this question, what this refers to findOneAndUpdate? From the code we can deduce that it is a Mongodb method, but the tags or the question say nothing about. In any case,…
-
0
votes1
answer223
viewsA: How to create a search box with Nodejs and Mongodb?
Note that in your own example you use find({ cliente: /Jean/i }), where find receives the object { cliente: /Jean/i }. Down below you try again passing { search } as parameter. As the value of…
-
1
votes1
answer480
viewsA: Js file import error (Node)
Despite the operator import be defined in the Javascript syntax, the Nodejs engine, V8, does not yet implement this operator. To import the module, you will need to use the function require as…
-
1
votes1
answer69
viewsA: Javascript variable created with get() in firestore document field
I cannot guarantee that your query is returning the expected result, but the problem I see in the example is that you are performing an input/output operation, and you are not waiting for the…
-
0
votes1
answer684
viewsA: Query with conditions using Mongodb Irrigation + nodejs
Understand how the pipelines of aggregate? Basically you are passing an array of commands to be executed in your database, the return of each command, is passed as input to the next. In the if code…
-
1
votes1
answer95
viewsA: Use function in datatables
Its function searches for all elements .Preco2 and apply the mask to these elements. Obviously this mask is only applied to existing elements in your document, if eventually a new .Preco2 for…
-
1
votes1
answer61
viewsA: How to use a const with middleware and Routes?
I see no need in using middlewares, you can declare a module as your database and access this module when necessary, do not need to attach it in your res. For example: // database.js const database…
-
0
votes2
answers383
viewsA: How to export and use a Local Middleware with Express Route?
You are passing the wrong parameters to the methods. The method route() of router takes only one parameter: the string with its path. Passing the middleware as the second parameter will have no…
-
5
votes1
answer9533
viewsA: Problem with promisse, returns: "Promise {<pending>} "
What you need to understand is that every function async returns a Promise. Behind the curtains, the following function: async function somar(a, b) { return a + b } It’s exactly the same as:…
-
2
votes1
answer1340
viewsA: Sending body parameter via fetch API
From the error message, one can assume that the error is in this section: passwd !== await user.passwd First to use await does not make any sense, but it will not cause an error, the problem is that…
-
2
votes2
answers63
viewsA: Allow only typing 123456 jquery
If the idea is to allow only digits from 1 to 6 in the input, I would avoid this approach of checking the typed key, it has flaws like: The user can click with the mouse and paste a text into the…
-
8
votes1
answer68
viewsA: Why is there result divergence depending on how the regular expression is executed in Javascript?
When you use the backslash \ within a string, you are escaping the next character. I mean, when you write "\." in literal string, your interpreter will understand as if you were trying to escape .,…
-
1
votes1
answer40
viewsA: Problems with Json and local Storage
The problem I’m seeing in your script is here: //armazenamento de ToDo no JS var todos = JSON.parse(localStorage.getItem('list_todos')) || [] ; //To do padrão var todos = [ 'Fazer cafe', 'Estudar…
-
0
votes1
answer2802
viewsA: Using Promise.resolve(). then() correctly Error: Uncaught (in Promise): Typeerror: Cannot read Property
This is a problem with the context of this. this refers to the object in which the method is executed, not to the object in which the method is declared. If your method openModal is passed as a…
-
2
votes1
answer63
viewsA: Variables bursting
It seems to me that you are corrupting the stack/stack memory. The variable classe_aux is a pointer that points to classe_main. classe_main in turn is a variable of type char, it stores only one…
-
2
votes2
answers1285
viewsA: How to define private attributes in a constructor function using javascript
This is not usually done in Javascript. There is a proposal in phase 3 of Ecmascript to include the private access method in the classes, but for now it is just that, a proposal. By convention, many…
-
2
votes1
answer48
viewsA: How to use ES6+ Spread to metamorphosize one object within another?
If you are to modify only one of the properties of an internal object, such as the endereco, you will have to deconstruct that internal object as well, otherwise you would just be overwriting the…
-
-6
votes2
answers151
viewsA: Operator ! in if ternary
In PHP, 1 and 0 are values truthy and falsy, they can be used as logical conditions, although their types are different from boolean. In your example you have $number % 2. As the value of $number is…
-
1
votes1
answer367
viewsA: Jquery validate (Rules)
Instead of using required: true, you can pass an object to the property required on condition that the input is mandatory or not. This object must have the property depends, where in this property…
-
0
votes2
answers37
viewsA: Problem with using Else
That’s because $result is not an array, it is an object of the type mysqli_result, then it makes no sense to use count($result) to check if he found the result or not. You should be checking the…
-
0
votes1
answer47
viewsA: Doubt in Javascript Map and findIndex
You have declared an array stores and assigned that same array to both scores of output. Since arrays are passed by reference, both arrays are the same, so when you add an item to an array, it…
-
2
votes1
answer55
viewsA: How to indicate that a variable is an Express object using Javascript Docs?
It is possible, if you create an annotation with the type of this variable. Intellisense accepts Jsdoc annotations to indicate the type of the variable with the following syntax: /** * @param {…
-
1
votes1
answer47
viewsA: PYTHON error index out of range
Elevate the condition if contagem == len(itens) to run before accessing itens[contagem] while True: if contagem == len(itens): break else: comb.append(i + itens[contagem]) print(comb) contagem =…
-
0
votes3
answers638
viewsA: Comparison of strings in exercise!
I’ve seen that same question several times on the site, and none of them offered enough context for a good answer. I believe that this question wants you to declare constants in your code to make it…
-
1
votes1
answer260
viewsA: Function with pEqual error
I do not think this question needs an answer, but as the user says that the code still does not work even with the correction in comparison, I will leave the snippet executable: function…
-
4
votes2
answers487
viewsA: Can anyone explain to me the meaning of the $ dollar symbol in Javascript?
var $item = $(this).parent().parent().find('input'); This is a code in jQuery. $ is a valid variable name, and the jQuery library by default defines a variable with the name $ as an alias for…
javascriptanswered Andre 5,836 -
0
votes1
answer131
viewsA: Global variable is not being assigned within an AJAX function
I’m not going in deep, but what’s happening here is an asyncronism. Note that in your AJAX you declare a callback function in the property success. Why do you need to declare a function instead of…
-
2
votes1
answer1005
viewsA: How to make a file return a value after 2 seconds
If you want to simulate a delay in your trial, you should put the setTimeout within your Precedent, before you invoke resolve() But why doesn’t your code work? Inside then and catch, you should…