var x = 10;
function abc(x)
{
console.log(x);
return x*10;
}
console.log (abc(x) + abc(x));
OUTPUT:
10
10
200
I don’t know how to ask this but in short, why is the output like that?
Blancer.com Tutorials and projects
Freelance Projects, Design and Programming Tutorials
Category Added in a WPeMatico Campaign
var x = 10;
function abc(x)
{
console.log(x);
return x*10;
}
console.log (abc(x) + abc(x));
OUTPUT:
10
10
200
I don’t know how to ask this but in short, why is the output like that?
I want to create a basic visualization, I have a two columns dataset and I got Incompatible data table: Error: Table contains more columns than expected (Expecting 2 columns)
0: Array [ "Country", "Impact of event" ]
1: Array [ "United Kingdom", 100000 ]
2: Array [ "Slovakia", 100000 ]
3: Array [ "Slovenia", 100000 ]
4: Array [ "Sweden", 100000 ]
5: Array [ "Romania", 100000 ]
6: Array [ "Portugal", 100000 ]
7: Array [ "Norway", 100000 ]
8: Array [ "Netherlands", 100000 ]
9: Array [ "Malta", 100000 ]
10: Array [ "Latvia", 1 ]
11: Array [ "Luxembourg", 100000 ]
12: Array [ "Italy", 100000 ]
13: Array [ "Ireland", 100000 ]
14: Array [ "Hungary", 100000 ]
15: Array [ "France", 100000 ]
16: Array [ "Finland", 100000 ]
17: Array [ "EU/EEA", 100000 ]
18: Array [ "Spain", 100000 ]
19: Array [ "Greece", 100000 ]
20: Array [ "Estonia", 1 ]
21: Array [ "Denmark", 100000 ]
22: Array [ "Czechia", 100000 ]
23: Array [ "Belgium", 100000 ]
24: Array [ "Austria", 100000 ]
length: 25
Any idea how can I solve this, or why is this happening?
I have this code that I am trying to use as a bookmarklet.
fetch('https://hf.space/embed/Alifarsi/news_summarizer/+/api/predict/', { method: "POST", body: JSON.stringify({"data":[ "https://www.cp24.com/news/ontario-reports-481-new-covid-19-cases-1-death-1.5667950"]}), headers: { "Content-Type": "application/json" } }).then(function(response) { return response.json(); }).then(function(json_response){ console.log(json_response) })
I got the code from:
https://hf.space/embed/Alifarsi/news_summarizer/api
Usually the bookmarklets start with “javascript:” keyword. I tried to added that at the start of the string, but it did not fetch the expected page.
I come here after two whole days without success.
I want to increment my array with the pictures selected by the User, for return to my database a list of uri. But when the user choosed the first picture and re-open the android navigator for take a new picture, I saw the array doesn’t increment.
It takes the first value, and when I leave the selectImage() method it is back to empty.
Here is my main function :
const arrayImage = [];
const selectImage = () => {
const options = {
maxWidth: 2000,
maxHeight: 2000,
storageOptions: {
skipBackup: true,
path: 'images'
}
};
launchImageLibrary(options, response => {
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
const source = { uri: response.assets[0].uri };
array ?
setImage(source)
: arrayImage.push(source)
console.log(arrayImage);
}
})
console.log(arrayImage)
I tried with promises, changing my function in async, with a SetTimeOut but I guess the probleme is not with the Asynchronous.
Someone for help ? Thanks a lot.
what I am Trying to do :
I am trying to save the data into database by sending data via a post request
please try to help when I am using similar code it is working but when I am copy pasting same code into this file its not working and showing same error
code of connecting database and model
const mongoose=require('mongoose');
const validator=require('validator');
mongoose.connect('mongodb://127.0.0.1:27017/task-manager-api',{
useNewUrlParser:true,
}).then(()=>{
console.log("connection successful");
}).catch((error)=>{
console.log(error);
})
const Task=mongoose.model('Task',{
name:{
type:String,
required:true,// making name compulsory to be entered
trim:true // trim will remove spaces
},
completion:{
type:Boolean,
required:true
}
})
// const me = new Task({
// name:'packing',
// completion:false
// })
// me.save().then(()=>{
// console.log(me)
// }).catch((error)=>{
// console.log(error);
// })
module.exports=Task
sending json
{
"name":"washing",
"completion":true
}
error while sending json via post
{
"errors": {
"completion": {
"name": "ValidatorError",
"message": "Path `completion` is required.",
"properties": {
"message": "Path `completion` is required.",
"type": "required",
"path": "completion"
},
"kind": "required",
"path": "completion"
},
"name": {
"name": "ValidatorError",
"message": "Path `name` is required.",
"properties": {
"message": "Path `name` is required.",
"type": "required",
"path": "name"
},
"kind": "required",
"path": "name"
}
},
"_message": "Task validation failed",
"name": "ValidationError",
"message": "Task validation failed: completion: Path `completion` is required., name: Path `name` is required."
}
**router file **
const express =require('express');
const router=new express.Router();
const Task =require('../2-mongoose/4-task');
router.get('/tasks' ,async(req,res)=>{
const data = await Task.find({})
res.send(data);
// console.log(data);
})
router.get('/tasks/:name',async(req,res)=>{
const dataname= await Task.find({name:req.params.name});
res.send(dataname);
// console.log(req.params);
})
router.post('/tasks',async(req,res)=>{
const task=new Task(req.body);
try{
await task.save();
console.log(req.body)
res.status(201).send(task);
}
catch(err){
res.status(404).send(err);
}
})
module.exports=router
and the main file
const express=require('express');
const app=express();
const router=require('../4-task-routers/task');
app.use(router);
app.use(express.json());
app.listen(8000,()=>{
console.log('server started broo');
})
I am injecting JS into page to do some AB tests.
In the first render of the page there is a code inside a that I would love to get, the problem is that this tag is getting remove by an other script after few seconds.
How can I get the first render of the page ?
I have ask similar question before and also have find a similar question here but they are mix in with node js and react js . I also tried using JSON stringify
and rewriting the code but still don’t know how to fix this.
This is what it show in console
[object Object]
let name = document.getElementById("name")
let age = document.getElementById("age")
let bttn = document.getElementById("btn")
let obj = {}
let arr = []
bttn.addEventListener("click", function() {
obj = {
name: name.value,
age: age.value
}
})
I encountered a problem when trying to use useRef react hook to add cssText in Typescript. I have tested the code in Javascript and it works perfectly fine but unable to make it work in Typescript. My code is as below. The code will change the background color of a div when I click the button.
import {useRef} from 'react';
function App() {
const divRef = useRef<HTMLDivElement>(null)
const handleClick = () => {
divRef.current && divRef.current.style.cssText += "background-color: blue";
}
return (
<div className="App" ref={divRef}>
<button onClick={handleClick}>Click me</button>
</div>
);
}
I got the following error message:
ERROR in src/App.tsx
Parsing error: ';' expected
webpack compiled with 2 errors
ERROR in src/App.tsx:6:52
TS1005: ';' expected.
My dependencies are as below:
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.1.1",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.0",
"@types/node": "^16.11.33",
"@types/react": "^18.0.8",
"@types/react-dom": "^18.0.3",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-scripts": "5.0.1",
"typescript": "^4.6.4",
"web-vitals": "^2.1.4"
},
Appreciate if anyone can share any insight into this issue.
I want to create a little game. For this purpose, I want a map (normal image) and some tokens (also normal images) on top of it. I found some solutions which fulfill some of my constraints, but not all of them. So my question is how to best achieve this?
I would welcome CSS over JavaScript for the most constraints.
Constraints:
Have a great day!
I am working on a react component which works with dynamic data which is an array, but its not working with the same array if I pass it statically. I could not figure out it.
Array is [ { data: [ [ 1650931200000, 92.92520141449552 ], [ 1651363200000, 90.94800749520344 ], [ 1651449600000, 92.75263509391628 ] ], pointStart: 1650931200000, pointInterval: 86400000 } ]
I have to write a function that takes a blog id as argument (e.g. ‘blog-1’ and ‘blog-2’), and then, from the element with an id that matches the argument, the function needs to select all the elements that has the attribute class=”content”. Finally, the function needs to return the elements obtained from the previous step.
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
</head>
<body>
<h2>Our Amazing Blogs</h2>
<div id="blog-1">
<h3>How to prepare the perfect pizza</h3>
<p class="content">
The secret for preparing the perfect pizza is.... #!/*?@, and ####@@@!</br>
So you just have to $%!?#**- it!
</p>
<p class="content">
<u>Upgrade to Pro to uncover the full post</u>
</p>
</div>
<div id="blog-2">
<h3>My life as a shrimp</h3>
<p class="content">
Few years back I got tired of all the pressure put on me just for the fact of being a human being.
Why does society expect you to behave like a person just for the fact of being one?!
So I decided to turn myself into a shrimp and what happend next is amazing...
</p>
<p class="content">
<u>Upgrade to Pro to uncover the full post</u>
</p>
</div>
</body>
</html>
Javascript base:
function getContentFromBlog(blogId) {
// Get the right div according to the given blogid
let blog = "Replace this string with the expression to get the blog div";
// Get all elements with content class from the blog div
let content = "Replace this string with the expression to get the elements with 'content' class from the blog div";
// Write the return statement to return content
}
The following snippet is taken from an example in Google API doc. The intriguing part of this snippet is that onload event handler in the two <script async> in <head> are defined later in the <body>. Does the onload event in the async script only fire after the <body> are parsed? Does any spec provide such guarantee? Or this code is only correct under the implied assumption that these two particular scripts in <head> takes a long time to fetch and execute?
<!DOCTYPE html>
<html>
<head>
<script async defer src="https://apis.google.com/js/api.js" onload="gapiLoad()"></script>
<script async defer src="https://accounts.google.com/gsi/client" onload="gisInit()"></script>
</head>
<body>
<script>
function gapiLoad() {
// do something
}
function gisInit() {
// do something
}
// there are other stuffs...
</script>
</body>
</html>
This is the Component Code- It is called the Tracker Chart
These are the imports
import React, { Component } from 'react';
import DatePicker from 'react-datepicker';
import 'react-datepicker/dist/react-datepicker.css';
This is the main code
changeDate(stateName, e){
this.setState({[stateName]: e});
console.log(stateName + e)
}
render() {
let filteredfiles = this.state.tracker.filter(
(file) => {
return file.root.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1;
}
);
return (
<div>
<h2 className='text-center'>Tracker Chart</h2>
<br></br>
<Row>
<div className="input-2">
<ExportReactCSV csvData={this.state.tracker} fileName={"Tracker Chart"} />
</div>
<div className= "input-1">
<input class= "form-control chosen-select" type = "text" align = "left" placeholder = "Search by Style Number Here"
value = {this.state.search}
onChange = {this.updateSearch.bind(this)}
/>
</div>
</Row>
<br></br>
<div className = 'row1'>
<table className='table table-striped table-bordered'>
<thead>
<tr>
<th>Ladder Plan</th>
<th>Style Number</th>
<th>Vendor</th>
<th>Size Range</th>
<th>FOB Cost</th>
<th>Total Quantity</th>
<th>CXL Date</th>
<th>Handover to Tech</th>
</tr>
</thead>
<tbody>
{
filteredfiles.map(
master =>
<tr key = {master.tID}>
<td>{master.lp}</td>
<td>{master.root}</td>
<td>{master.vendor}</td>
<td>{master.actSize}</td>
<td>{master.totFcost}</td>
<td>{master.totalQty}</td>
<td>{master.cxlDate}</td>
<td><DatePicker
dateFormat = 'dd/MM/yyyy'
selected = {this.state.techHandover} placeholderText="Select Date"
onChange= {this.changeDate.bind(this, 'techHandover')}
maxDate = {new Date()}
filterDate = {date => date.getDay() !== 0}
showYearDropdown
scrollableMonthYearDropdown
/>
</td>
</tr>
)
}
</tbody>
</table>
</div>
</div>
);
}
}
export default TrackerComponent;
I have multiple rows in my table, and the date picker sets the same date that is picked by the user for one row, across all rows. Kindly suggest how to solve this problem.
The date picker is being utilized in the ‘Handover to Tech’ Column.

What is the best way to split a svg triangle into 5 random pieces in JavaScript?