How to calculate savings from given value with function? [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Should I calculate a savings of 15 % given an amount x?
function main(){
var salaryAmount = parseInt(readLine(), 10);
// Complete the function call
getSaving();
}
// Complete the function
function getSaving(){
};

If I understand the problem correctly, you are trying to create a function which tells you how much you would need to save in order to be saving 15% of any given salary.
function main(){
var salaryAmount = parseInt(readLine(),10);
var saving = getSaving(salaryAmount); // we pass the salary to the function
}
function getSaving(salary){ // we add a parameter for the salary
return salary * 0.15; // we multiply the salary by 15% and return that value
};
we could then simplify this code and remove the second function altogether.
function main(){
var salaryAmount = parseInt(readLine(),10);
var saving = salaryAmount * 0.15; // we calculate the savings here
}
Hope this is the answer you were looking for!

Related

Does one push everytime creates array inside of array? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 days ago.
Improve this question
I created button that is generate a random number every time , but in the console log it shows it like this:
small project i have been working on during course of javascript
I tried to make one array of random numbers and when it reach above 4 random numbers i will use Shift method to erase one. ( I also tried to use for loop )
What actually happen that is it kind of creates me new array inside of the orginal array
let randomArr = [];
if (randomArr.length >= 4) {
randomArr.shift();
lastNumbers.textContent -= randomArr + ",";
return randomArr;
} else {
randomArr.push(randomNumber);
// randomArr.length = randomArr;
lastNumbers.textContent += randomArr + ",";
// return randomArr;
}
Ty for helping!

Can i convert math.js object into JavaScript function? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm developing simple js neural network and need to create javascript function (derivative of entered by user) before learning starts.
I know about evaluate(), but i think it'll be slowly than simple function.
That is what i want:
const derivative = math.derivative('x^2/sin(2x)', 'x');
const derivative_func = derivative.please_stay_func();
...
while(1) alert(derivate_func(12)) //:) alert result of (2 * 12 * Math.sin(2*12) - 2 * Math.pow(12, 2) * Math.cos(2*12)) / Math.pow(sin(2*12), 2)
Is it real? And maybe i'm not right about speed. Maybe there is some better ways - write here.
i am on mobile, please edit this
maybe this is want you want to do
const countThings = (customValue) ==>{
let x = 'x^2/sin(x)';
let y = 'x';
x = math.parse(x)
y = math.parse(y)
return math.derivative(x, y).evaluate({x:customValue});}
console.log(countThings(12))
and don't do while(1) alert because it will keep alerting

Integer comparison within score board app, score difference equal two [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I'm writting an score board app.
Got two integers, i need to compare them, for example
to know when game should be ended, eg. score = 20:22, 24:26 (score difference to end the game should be equal to two)
How i can make such comparison with js?
You can use split() method to separate scores into two different elements, and then afterwards just compare them.
function isGameOver(score, differenceToWin) {
var scoreArray = score.split(":");
return Math.abs(scoreArray[0] - scoreArray[1]) > differenceToWin;
}
isGameOver('24:26', 2)
EDIT: In case you only need to compare two integers, go ahead and use only the return statement line:
var score1 = 24;
var score2 = 26;
var differenceToWin = 2;
var isGameOver = Math.abs(score1 - score2) > differenceToWin;

How to make setInterval work? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So here is my code and I want to add 1 to total every second`
var doughnut = 0;
function myFunction(){
document.getElementById("total").innerHTML = " total: " + setInterval(doughnut +1, 1000) ;
}
Can you explain me how setInterval() works and where to put it?
setInterval accepts two arguments:
The "What": The function to execute
The "When": interval time in milliseconds to execute that function
Basically each second (1000 ms) the function increments the doughnut value and writes the updated value to the HTML element with id total.
Try this:
var doughnut = 0;
setInterval(function () {
doughnut++;
document.getElementById("total").innerHTML = " total: " + doughnut;
}, 1000);

how to change constructor value JS [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to change constructor base value like I have:
function G()
{
this.speed=1;
}
and var k=new G(); gives me k.speed=1;
now I want that every time I create new G , its speed was like 10;
I tried
G.changeSpeed=function(){this.speed=10;}
G.prototype.changeSpeed=function(){this.speed=10;}
second works on already initialised ones, but first doesn't work at all ( error ).
any way I can do it?
How about:
function G(speed)
{
this.speed = speed;
}
You can do:
var x = new G(1); // x.speed = 1;
var y = new G(2); // y.speed = 2;

Categories

Resources