My code here
if (parent4 && parent5 && parent6 && (_state[tree][parent4]) + (_state[tree][parent5]) + (_state[tree][parent6]) !== 8) {
return false;
} else {
return true;
}
It works, and has some of the elements I want, namely that if the sum of the three _states !== 8, it returns false.
I'll try to explain the logic I'm trying to achieve as simply as I can:
if par4 + par5 + par6 !>= 8
return false
if par4 + par5 !>= 8
return false
if par4 OR par5 OR par6 !>= 8
return false
else
return true
I abbreviated the code for simplicity and ease of understanding.
Swapping around return false and return true and changing it to >= doesn't work, because for all elements, even ones I don't mention here, it needs to go to return true by default.
How about this?
if (parent4 && parent5 && parent6) {
if ((_state[tree][parent4] + _state[tree][parent4] + _state[tree][parent4]) !== 8) {
return false;
} else {
return true;
}
}
Or in a one-liner:
if (parent4 && parent5 && parent6 && (_state[tree][parent4] + _state[tree][parent4] + _state[tree][parent4]) !== 8) {
return false;
} else {
return true;
}
Related
I'm working with Vue in a Laravel app. Everything below works except the last one. I can't seem to find the right search terms to fit this situation. Sorry if it's a duplicate.
Here is my current code:
return [...this.tableData].filter((salesorders) => {
if (this.selectOption == '6') {
return salesorders.order_status.match(this.status);
}
if (this.selectOption == '1') {
return salesorders.number.includes(this.searchInput);
}
if (this.selectOption == '2' && this.choice == 'is') {
var ship_date = moment(String(this.first_date)).format('MM-DD-YYYY');
return salesorders.requested_ship_date.match(ship_date);
}
if (this.selectOption == '2' && this.choice == 'is not') {
var ship_date = moment(String(this.first_date)).format('MM-DD-YYYY');
return !salesorders.requested_ship_date.match(ship_date);
}
if (this.selectOption == '2' && this.choice == 'is between') {
var ship_date1 = moment(String(this.first_date)).format('MM-DD-YYYY');
var ship_date2 = moment(String(this.end_date)).format('MM-DD-YYYY');
return salesorders.requested_ship_date >= ship_date1 && salesorders.requested_ship_date >= ship_date2;
}
});
I just figured it out:
return salesorders.requested_ship_date >= ship_date1 && salesorders.requested_ship_date <= ship_date2;
I have a function that has to act different if pan.cost > 0.
So let's say curPos = 3 and pan.cost = -1
Now when I do this, no matter what, if(curPos + 1 === 5 || 30) is always used even if curPos + 1 is 2,3,4,6 etc (as long pan.cost < 0)
Now I have put console.log(curPos + 1) inside the else if-statement and it also says their that it does not meet the requirements.
function action(curPos)
{
var pan = panel[curPos];
if(pan.cost > 0)
{
}
else if(curPos + 1 === 5 || 39)
{
console.log(curPos + 1);
}
else if(curPos + 1 === 3)
{
console.log("should be here");
}
}
Try this:
function action(curPos)
{
var pan = panel[curPos];
var newCurPos = (curPost + 1);
if(pan.cost > 0)
{
}
else if(newCurPos === 5 || newCurPos === 39)
{
console.log(newCurPos);
}
else if(newCurPos === 3)
{
console.log("should be here");
}
}
The line
curPos + 1 === 5 || 39
always evaluates to truthy, because it is read:
(curPos + 1 === 5) || 39
and 39 is a truthy value.
if(curPos + 1 === 5 || 39) will always evaluate to true. Look at the part after your or pipes. if(39) will always be true.
|| 39 will always return true and pan.cost doesn't exist.
Right now the !isValid is not accepting any values in the input for current balance. Is there another way to verify the value in the input? JSFiddle
The function in question:
function isValid(entry, a, b)
{
if (isNaN(entry.value) || (entry.value==null) || (entry.value=="") || (entry.value < a) || (entry.value > b)) {
alert("Invalid entry. Your min payment should be between " + a + " and " + b + ".")
return false
}
return true
}
// send entries to validation function
// exit if not valid
if (!isValid(currentBalance, 0, 10000)) {
return false
} else if (!isValid(interest, 0, 30)) {
return false
} else {
return true;
}
if (!isValid(mnth_pay, currentBalance*.02, currentBalance)) {
return false
} else {
console.log("do nothing");
}
I've just adjusted your Fiddle.
As I first added console.msg to get the values handled by the function isValid(entry, a, b), I noticed that entry.value is undefined, but entry matches the current input.
Adjusting to
function isValid(entry, a, b)
{
if (isNaN(entry) || (entry==null) || (entry=="") || (entry < a)
|| (entry.value > b))
{... }
}
seems to fix the issue.
if ((value.length == 12) || (value.length == 9)) {
if ((value.length == 12)) {
if (value.substring(0, 2) = "048") { //this doesn't work in the execution
return true;
} else {
return false;
}
}
if ((value.length == 9)) {
return true;
} else {
return false;
}
} else {
return false;
}
You need == like this. you cant have a single = in an if statement
if (value.substring(0,2)=="048"){
It is because you are using the JS assignment operator. Typically var a = 123;
You want to be using === since it doesn't do type coercion. As opposed to == which does.
if (value.substring(0,2) === "048") {
// etc
}
I recently filled out a form and when I got to the phone number textBox I noticed some really cool things going on. As I entered my number, general phone symbols were getting added automatically. Example:
I start entering my area code '555'
and my input was changed to 1 (555)
to test what just happened I backspaced on the ) and it quickly added it back in.
So my question is, how do I get this input to happen?
I use a javascript library called automask - you dont see the mask but it wont let you type anything outside the mask
for instance if your mask is ###-###-#### then any other characters are ignored (ie not 0-9) and the dashes are put in automatically.
I can post the library if you would like to take a look at
example of implementation
<input type=text name=ssn onkeypress="return autoMask(this,event, '###-##-####');">
// email kireol at yahoo.com
// autoMask - an adaption of anyMask
//
// this will force #'s, not allowing alphas where the #'s are, and auto add -'s
function autoMask(field, event, sMask) {
//var sMask = "**?##?####";
var KeyTyped = String.fromCharCode(getKeyCode(event));
var targ = getTarget(event);
keyCount = targ.value.length;
if (getKeyCode(event) < 32)
{
return true;
}
if(keyCount == sMask.length && getKeyCode(event) > 32)
{
return false;
}
if ((sMask.charAt(keyCount+1) != '#') && (sMask.charAt(keyCount+1) != 'A' ) && (sMask.charAt(keyCount+1) != '~' ))
{
field.value = field.value + KeyTyped + sMask.charAt(keyCount+1);
return false;
}
if (sMask.charAt(keyCount) == '*')
return true;
if (sMask.charAt(keyCount) == KeyTyped)
{
return true;
}
if ((sMask.charAt(keyCount) == '~') && isNumeric_plusdash(KeyTyped))
return true;
if ((sMask.charAt(keyCount) == '#') && isNumeric(KeyTyped))
return true;
if ((sMask.charAt(keyCount) == 'A') && isAlpha(KeyTyped))
return true;
if ((sMask.charAt(keyCount+1) == '?') )
{
field.value = field.value + KeyTyped + sMask.charAt(keyCount+1);
return true;
}
return false;
}
function getTarget(e) {
// IE5
if (e.srcElement) {
return e.srcElement;
}
if (e.target) {
return e.target;
}
}
function getKeyCode(e) {
//IE5
if (e.srcElement) {
return e.keyCode
}
// NC5
if (e.target) {
return e.which
}
}
function isNumeric(c)
{
var sNumbers = "01234567890";
if (sNumbers.indexOf(c) == -1)
return false;
else
return true;
}
function isNumeric_plusdash(c)
{
var sNumbers = "01234567890-";
if (sNumbers.indexOf(c) == -1)
return false;
else
return true;
}
function isAlpha(c)
{
var lCode = c.charCodeAt(0);
if (lCode >= 65 && lCode <= 122 )
{
return true;
}
else
return false;
}
function isPunct(c)
{
var lCode = c.charCodeAt(0);
if (lCode >= 32 && lCode <= 47 )
{
return true;
}
else
return false;
}
If this was an aspx page, they were probably using the AJAX Control Toolkit MaskedEdit Extender. There is also the Masked Input plugin for jQuery.