Javascript logic statement - I got 99 problems [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 8 years ago.
Improve this question
...but a glitch ain't one.
Hey there, I am still learning so I apologize for the simple question. I'm just trying out a hypothetical logic statement that would still make sense using javascript.
Example:
if (problems == 99) {
glitch != 1
}
Basically, I'd like it to mean "If I have 99 problems, a glitch isn't one of them" in the shortest code I can muster. Any help is really appreciated!!

Even shorter
glitch = problems !== 99;
Here's a more lyrical version:
if (problems.length === 99 && problems.indexOf("glitch")=== -1){
return "HOVA";
}

You are not setting glitch. Try glitch = false instead

Related

How to set variable of image src and use in 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 2 years ago.
The community is reviewing whether to reopen this question as of 2 years ago.
Improve this question
So if i have some codes like this
If(sceneA){document.getElementById("divA").src="A.png";}
If(document.getElementById("divC")=="A.png"){document.getElementById("divB").src="B.png";}//And alot of codes here
How can I use a var to shorten strings like
document.getElementById("divA").src="A.png"
document.getElementById("divB").src="B.png"
so i can use them both inside (IF) and {function}
As they have to repeat quite a few times in the codes.
Thanks alot!
That's exactly what functions are for.
Define a function for repeating blocks of code as follows:
function setSrc(divName, imgName){
document.getElementById("div"+divName).src = imgName+".png";
}
function srcEquals(divName, imgName){
return (document.getElementById("div"+divName).src == imgName+".png");
}
Then you can replace your code with this:
if(sceneA){setSrc("A","A");}
if(srcEquals("C", "A")){setSrc("B","B");}

What is an example of a "custom function" and "recursion" [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 years ago.
Improve this question
I have been asked to show I have used these processes in my program but from looking up the definitions, I don't know what they mean. I am confident my program is complicated enough that it uses these processes, but I don't know exactly what they are. What would be an example of these processes used in javascript?
Unsure what you mean by custom function - but recursion is just a function that calls itself.
Example of recursion
countNumTimesToZero = (myNum, count = 0) => {
if (myNum - 1 === 0) return count + 1;
return countNumTimesToZero(myNum - 1, count + 1);
}

For loop JS for a calculator [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 5 years ago.
Improve this question
I'm trying to create a calculator which goes through 18 units. I wanted to make my code shorter by using a for loop. I thought something like this would work:
var i=0;
for (i=0;i<=18;i++)
{
if (Unit[i] = "P" or Unit[i] == "p")
{
UnitTotal[i] = 70;
SetCookie('UnitAns'[i],UnitAns[i]);
}
}
This doesn't work what am I doing wrong or what do I need to do differently?
Unit[i] = "P"
Unless it throws an exception because Unit isn't defined, this will always be true. = is an assignment, not a comparison.
or
or is not a keyword in JavaScript. The OR operator is ||.

Using if statement inside if statement, good or bad practice? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Is it OK to use if statement in this form, or should i need to use something else to get result. I want to get effect if filtration is on 100 % then check cX if is on 100 % to add sign-ok not before filtration is on 100 %.
Just need opinion is it a good coding or I should change the approach?
if (filtration === 100) {
$(".filtration").removeClass('sign-no');
$(".filtration").addClass('sign-ok');
if (cX === 100){
$(".cX").removeClass('sign-no');
$(".cX").addClass('sign-ok');
if (stripping === 100) {
$(".stripping").removeClass('sign-no');
$(".stripping").addClass('sign-ok');
if (precipitation === 100) {
$(".precipitation").removeClass('sign-no');
$(".precipitation").addClass('sign-ok');
}
}
}
}
No issues. You can use. But if only first condition is true, then second condition will be checked and if it is true only it check the third condition and likewise.
Its okay, you can do it. But if you set a value on code quality, you should use maximal 2 depth in a block.
Must Code Quality Tools has a configuration for it.
ESLint
JSLint
....

Correct inputs for this? [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 9 years ago.
Improve this question
I am trying to take a survey you can say: I am asking a question if they work out a lot or not, then I have different questions for them if they do or don't work out a lot. And then I am asking them if they are female or male. My goal is to give them feedback based on all three things, sex,work out or not, and how they answer questions.
Currently all of my questions go to the same inputs, for the 2 sets of questions. My code is to long to post so I will add a fiddle below .
$('.myOptions').change(function () {
$('.list').removeClass('active');
$('.' + this.value).addClass('active');
});
http://jsfiddle.net/7xM2f/12/
Your braces are not properly nested. For example you have something like
if (tt == 'Male') {
//some code
if (tt == 'Female') {
You are missing the closing brace for the Male block.
There are several such errors. You should properly indent your code to make these easier to track and pay attention to the error console.
http://jsfiddle.net/ExplosionPIlls/7xM2f/15/

Categories

Resources