function someNumber(num1, num2) { var result = num1 + num2; console.log(result); }
someNumber(10, 10);
I don’t know what’s happening in my someNumber function. Error : home.js:35 Uncaught TypeError: someNumber is not a function at home.js:35
Blancer.com Tutorials and projects
Freelance Projects, Design and Programming Tutorials
Category Added in a WPeMatico Campaign
function someNumber(num1, num2) { var result = num1 + num2; console.log(result); }
someNumber(10, 10);
I don’t know what’s happening in my someNumber function. Error : home.js:35 Uncaught TypeError: someNumber is not a function at home.js:35
I am trying to programmatically connect to my AWS EKS cluster using the official k8s JavaScript Client. I wanted to try and use loadFromOptions()
, instead of loadFromDefault()
. So, from the README.md
of the library repo, I was able to come up with the following
const k8s = require('@kubernetes/client-node');
const kc = new k8s.KubeConfig();
const cluster = {
name: 'NAME',
server: 'SERVER',
};
const user = {
name: 'NAME',
exec: {
apiVersion: 'client.authentication.k8s.io/v1alpha1',
args: [
'--region',
'us-east-1',
'eks',
'get-token',
'--cluster-name',
'NAME',
],
command: 'aws',
env: [
{
name: 'AWS_PROFILE',
value: 'NAME'
}
]
}
}
const context = {
name: 'NAME',
user: user.name,
cluster: cluster.name,
};
kc.loadFromOptions({
clusters: [cluster],
users: [user],
contexts: [context],
currentContext: context.name,
});
const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
k8sApi.listNamespacedPod('default').then((res) => {
console.log(res.body);
});
But unfortunately, I am hit with this error, where am I going wrong?
Normally an Error class has properties such as name, code, message, stack etc. Some special errors such as OpenSSL Error uses Error class but also have opensslErrorStack etc. How can I print all properties in an Error?
I tried:
process.on('uncaughtException', function(err) {
for (let i in err) {
console.log(i + ': ' + err[i]);
}
});
So I’m trying to solve the third problem of Project Euler in which you have to get the largest prime factor of a number. I’m trying this problem via freeCodeCamp. I pass all tests of 2, 3, 5, 7, 8 and 13195, but from 13195 and upwards I get a Potential infinite loop detected on line 12. Tests may fail if this is not changed.
warning. The final test of 600851475143 gives the following warnings:
Potential infinite loop detected on line 6. Tests may fail if this is not changed.
Potential infinite loop detected on line 15. Tests may fail if this is not changed.
Potential infinite loop detected on line 12. Tests may fail if this is not changed.
and the horribly wrong answer of 104441.
What could I have done wrong, since my loops don’t look like they would run infinitely syntax-wise? Am I missing something here?
Code I’m using:
const eratoSieve = (n) => {
let primes = [2, 3, 5, 7];
if (n > 7)
{
primes = [];
for (let i = 2; i < n; i++)
{
primes.push(i);
}
}
for (let j = 0; j < primes.length; j++)
{
let currentMultiple = primes[j];
for (let k = j + 1; k < primes.length - 1; k++)
{
if (primes[k] % currentMultiple === 0)
{
primes.splice(k, 1);
}
}
}
return primes;
};
function largestPrimeFactor(number) {
let primeNums = eratoSieve(number);
console.log(primeNums);
let biggestPrime = 0;
primeNums.forEach(elem => {
(number % elem === 0) ? biggestPrime = elem : 0;
});
return biggestPrime;
}
console.log(largestPrimeFactor(100));
Thanks in advance for the help!
Let’s say I am working on my feature branch A. After all my changes are pushed into the development branch B, it is merged by a senior developer. As per the requirement development branch is merged to master which is done by another developer. So, a developer who is viewing the development branch before merging to master wants changes in my code. How do I commit my new changes? Do I choose my previous feature branch to push new changes or create a new branch?
import React from 'react';
import { Tabs, Button } from 'antd';
import 'antd/dist/antd.css';
const { TabPane } = Tabs;
class App extends React.Component {
constructor(props) {
super(props);
this.newTabIndex = 0;
const panes = [
{ title: 'Tab 1', content: 'Content of Tab Pane 1', key: '1' },
{ title: 'Tab 2', content: 'Content of Tab Pane 2', key: '2' },
{ title: 'Tab 3', content: 'Content of Tab Pane 3', key: '3' },
];
this.state = {
activeKey: panes[0].key,
panes,
};
}
onChange = activeKey => {
this.setState({ activeKey });
console.log(activeKey);
};
onEdit = (targetKey, action) => {
this[action](targetKey);
};
add = targetKey => {
const {panes} = this.state;
let { activeKey } = this.state;
if (targetKey !== activeKey){
panes.push({title:'Tab 3', content:'Content of tab pane 3',key: activeKey+1})
this.setState({ panes, activeKey });
console.log(activeKey);
}
};
remove = targetKey => {
let { activeKey } = this.state;
let lastIndex;
this.state.panes.forEach((pane, i) => {
if (pane.key === targetKey) {
lastIndex = i - 1;
}
});
const panes = this.state.panes.filter(pane => pane.key !== targetKey);
if (panes.length && activeKey === targetKey) {
if (lastIndex >= 0) {
activeKey = panes[lastIndex].key;
} else {
activeKey = panes[0].key;
}
}
this.setState({ panes, activeKey });
};
render() {
return (
<div className="tab-section">
<div style={{ marginBottom: 16 }}>
<Button onClick={this.add}>ADD Tab-1</Button>
<Button onClick={this.add}>ADD Tab-2</Button>
<Button onClick={this.add}>ADD Tab-3</Button>
</div>
<Tabs
hideAdd
onChange={this.onChange}
activeKey={this.state.activeKey}
type="editable-card"
onEdit={this.onEdit}
>
{this.state.panes.map(pane => (
<TabPane tab={pane.title} key={pane.key}>
{pane.content}
</TabPane>
))}
</Tabs>
</div>
);
}
}
export default App;
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
import React from 'react';
import { Tabs, Button } from 'antd';
import 'antd/dist/antd.css';
const { TabPane } = Tabs;
class App extends React.Component {
constructor(props) {
super(props);
this.newTabIndex = 0;
const panes = [
{ title: 'Tab 1', content: 'Content of Tab Pane 1', key: '1' },
{ title: 'Tab 2', content: 'Content of Tab Pane 2', key: '2' },
{ title: 'Tab 3', content: 'Content of Tab Pane 3', key: '3' },
];
this.state = {
activeKey: panes[0].key,
panes,
};
}
onChange = activeKey => {
this.setState({ activeKey });
console.log(activeKey);
};
onEdit = (targetKey, action) => {
this[action](targetKey);
};
add = targetKey => {
const {panes} = this.state;
let { activeKey } = this.state;
if (targetKey !== activeKey){
panes.push({title:'Tab 3', content:'Content of tab pane 3',key: activeKey+1})
this.setState({ panes, activeKey });
console.log(activeKey);
}
};
remove = targetKey => {
let { activeKey } = this.state;
let lastIndex;
this.state.panes.forEach((pane, i) => {
if (pane.key === targetKey) {
lastIndex = i - 1;
}
});
const panes = this.state.panes.filter(pane => pane.key !== targetKey);
if (panes.length && activeKey === targetKey) {
if (lastIndex >= 0) {
activeKey = panes[lastIndex].key;
} else {
activeKey = panes[0].key;
}
}
this.setState({ panes, activeKey });
};
render() {
return (
<div className="tab-section">
<div style={{ marginBottom: 16 }}>
<Button onClick={this.add}>ADD Tab-1</Button>
<Button onClick={this.add}>ADD Tab-2</Button>
<Button onClick={this.add}>ADD Tab-3</Button>
</div>
<Tabs
hideAdd
onChange={this.onChange}
activeKey={this.state.activeKey}
type="editable-card"
onEdit={this.onEdit}
>
{this.state.panes.map(pane => (
<TabPane tab={pane.title} key={pane.key}>
{pane.content}
</TabPane>
))}
</Tabs>
</div>
);
}
}
export default App;
Here is the code. Initially I should’nt see the tab. Onclick of the button, that particular tab should pop. I could just add a similar Tab everytime. If the tab is already present then it shouldn’t pop again.
Note- “antd”: “^4.16.13”
“react”: “^17.0.2”,
“react-dom”: “^17.0.2”,
“react-scripts”: “4.0.3”, are the packages used.
Here is the output that I get, everytime on Click of Add button, it pops the same tab-
https://i.stack.imgur.com/KhHMz.png
Please help me out in adding each tab on add button click.
I am trying to hide my glob.variables from DevTools(Console) by using Self-invoked function (IIFE)
Yes it does hide them, however AS other functions (e.g. arrow functions) are inside the IIFE, when called, it says function not defined.
When I take all functions outside of IIFE, they cannot use the variables which are inside the IIFE (e.g. products[], isAdmin).
What is the best practice of doing this?
<script>
// (function() {
let isAdmin = "<?php echo $is_admin ?? false; ?>";
let products = [];
document.addEventListener("DOMContentLoaded", async () => {
initDataTable();
if(!isAdmin) {
await initProducts();
}
});
const initDatatable() => { ... }
const initProducts = () => {
// response = ajax call result
products = response;
// return promise
}
// ... other functions
// })();
</script>
I wanted to use @keyframes, so I did this:
div {
width: 100px;
height: 100px;
background: red;
position: relative;
animation: action 5s infinite;
}
@keyframes action {
0% {top: 0px;}
25% {top: 200px;}
75% {top: 50px}
100% {top: 100px;}
}
However, this code runs when the page loads. Is there a way to trigger the @keyframes at a certain time with js? eg.
for (var i = 0; i < 10; i++) {
//Do something
}
//Activate @keyframes
Thanks!
I can open the Chrome DevTools console for this URL: https://www.google.com/ and enter the following command to print “Hello world!” to the console:
console.log("Hello world!")
However, when I attempt to use the same command for this URL: https://svc.mt.gov/dor/property/prc my message isn’t printed in the console. Why is that?
Is there any way to force the console to work for this MT website?
I’ve tried using python/selenium to open the page and execute_script() to issue the command, but that hasn’t worked either.
I’m making a small online multiplayer game with JavaScript and the native Canvas API (WebGL). I want to find the color of pixels on the screen as a form of collision detection, I figure it’d save resources to not have to process every shape every frame, but rather to simply check if the color of a pixel at a certain position is such that it is contacting a shape. (I hope that makes sense)
I ran some tests and I have an average frame delay of about 4-5 milliseconds without collision detection, and then when I make a single call to my canvas context’s .getImageData()
method, suddenly that frame delay shoots up to 19-20 milliseconds…
As far as I can find online getImageData()
is the only means of checking the color of a given pixel, but I have to think there’s some other way that doesn’t introduce such a huge amount of lag.
I tried running getImageData()
on a small section of the screen vs larger sections, and a 1×1 pixel request introduces 10ms latency, where a 600×600 pixel request is about 15ms… So the issue isn’t the amount/size of the request, but rather just the request itself is extremely slow, so there’s no potential for optimization here, I NEED another way.
Also, caching the image data is also not an option. I need to poll these pixels every single frame, I can’t cache it (because the player and the object it needs to collide with are all constantly moving, and they’re being controlled over the internet so there’s also no way of predicting where they’ll be at any given time… I NEED to poll every frame with no exceptions)
I am using Quasar, vue and vuex. I have created a layout and would like to use jest to unit test.
I have been copying bits of my layout code and running test as I go along.
This is my spec code
import MainLayout from "../../../src/layouts/test";
import { mountFactory } from "@quasar/quasar-app-extension-testing-unit-jest";
import { QLayout, QHeader, QToolbar, QBtn, QToolbarTitle, QImg } from "quasar";
const factory = mountFactory(MainLayout, {
mount: { type: "full" },
quasar: {
components: { QLayout, QHeader, QToolbar, QBtn, QToolbarTitle, QImg },
},
});
describe("test", () => {
it("Show leftdrawer if leftDrawer is true", async () => {
const wrapper = factory(MainLayout);
await wrapper.vm.$nextTick();
expect(wrapper.findComponent("button").isVisible()).toBe(true);
});
});
When I add this part in my MainLayout.vue
<div v-if="!isAuthenticated">
<q-btn
@click="goTo('signin')"
outline
roundeded
label="sign in"
name="signin"
class="q-mr-sm"
>
And This part
computed: {
...mapState("member", {
isAuthenticated: (state: MemberState) => state.isAuthenticated,
})
},
I get this error when testing
TypeError: Cannot read properties of undefined (reading ‘state’)
...mapState("member", {
isAuthenticated: (state: MemberState) => state.isAuthenticated,
})
How do I set up my spec file so that it reads in isAuthenticated from state in store.
I need to set my webPage from beginning to start. So I write code like this.
function BasicDetails() {
React.useEffect(()=>{
scrollView();
}, []);
function scrollView() {
document.getElementById('main-root').scrollIntoView({behavior: 'smooth'});
}
return (
<Nav>
<div id="main-root" style={{scrollBehavior: 'smooth'}}>
<div>
<Header pageTitle={'Shop Settings'}/>
<Button
onClick={saveBasicDetails}
variant="contained"
id='save'
className={classes.saveButton}>
SAVE
</Button>
</div>
<BasicDetailsData style={{scrollBehavior: 'smooth'}} ref={childRef}/>
</div>
</Nav>
);
}
But When I Tried to run my code, I have an error TypeError: Cannot read properties of null (reading ‘scrollIntoView’)
So I tried many times but can’t find the error.
I am a new student for react, so. I don’t know much about it.
Anyone can help me with this…I really need your help..thank you.
Can anyone tell me that how we can download maps and graph in react native
please help it this, i am not able to find any solution for this
I imported a project and when I try todo something that calls the symlink I get this error:
Here is the console
Here is the file with the error:
Here is the file with the error:
I tried reimporting the project multiple times on different IDE’s
I am working on html file. I have two two labels(say L1 and L2). Each label has two radio buttons. I want to hide L2 and it’s radio buttons if a user selects any radio button from L1.
I know this can be done using java script but how to capture the selection of radio buttons on which i can execute my java script.