windows phone 8 orientation control with if statement - windows-phone-8

I want to check current orientation of screen with if statement for example.
if(orientation==landscape)
{
a++;
}
What should i use for this kind of job how can i get my current orientation and check it with if statement.

ok i solved my problem
else if (p.X > 10 && p.X < 100 && a >= 1 && Orientation==PageOrientation.Landscape)
{
a--;
link = "cevsen/" + a.ToString() + ".jpg";
}
you can get your current orientation with Orientation and compare PageOrientation.Landscape

Related

Function for calculating pre-set commissions within google sheets

I am trying to create a function for calculating a pre-set commission within google sheets. I keep on getting a syntax error for line 15.
Can anyone help me? there is a description of what I am trying to achieve commented on the top.
Thanks.
/**Calculates commission based on the following rules
if less than 33 subtract 3
if in between 33.01 and 55 subtract 5
if in between 55.01 and 100 subtract 10
if more than or equal to 100 multiply by .9
*/
function comS(input) {
if (input <= 33) {
return (input - 3);
}
else if (input >= 33.01 && <= 55) {
return (input - 5);
}
else if (input >= 55.01 && <= 100) {
return (input * 0.9);
} else {
return "Please insert a valid amount"
}
}
/**
End of function
*/
That's not how && operators work, you need to set the comparison on each side:
(input >= 55.01 && input <= 100)
Also, take a moment to look on how to make a good question on SO.
https://stackoverflow.com/help/how-to-ask

AS3 Calculate if object is on other object and change Dynamic text

So I have this function. What it is supposed to do is calculate whether the Raisin cookie is on the plate (I have already declared all vars correctly) and have a dynamic text display the calorie count. When the cookie is out of the plate, then the calorie count should deduct the calorie count of the cookie (it should not reset as I have other cookies as well). The raisinOnce is a boolean that safeguards that the calories are not deducted before the cookie is added to the plate at least once.
function caloriesf(e:Event)
{
calories.text="only "+String(caloriesv)+" calories!";
if (((raisin.x > plateminx && raisin.x < platemaxx)&& (raisin.y > plateminy && raisin.y < platemaxx))&& raisinInPlate==false)
{
raisinOnce=true;
caloriesv+=50;
raisinInPlate=true;
return;
}
else if (((raisin.x < plateminx && raisin.x > platemaxx)&&(raisin.y < plateminy && raisin.y > platemaxx)) && raisinOnce==true)
{
raisinInPlate=false;
caloriesv-=50;
}
}
Now this works correctly when the cookie is added to the plate, but not when it is removed! What is wrong here?
I figured it out. The problem was that the else didn't need statements and also I didn't need to use the Once boolean...the corrected code as follows (works)
function caloriesf(e:Event)
{
calories.text="only "+String(caloriesv)+" calories!";
if ((raisin.x > plateminx && raisin.x < platemaxx)&& (raisin.y > plateminy && raisin.y < platemaxy))
{
if (raisinInPlate==false)
{
caloriesv+=50;
raisinInPlate=true;
}
}
else
{
if (raisinInPlate==true)
{
raisinInPlate=false;
caloriesv-=50;
}
}
}

Only follows second parameter

in the following code script for google Spreadsheets, I tried to make a program in which two pieces of information would be inputted to return a desired value that depends on BOTH values. Say, getValcharge ("OptionA", 2000) would return "76", or getValcharge ("OptionB",6000) would return 70. However, it seems to me that I keep getting returned the very last value possible: getValcharge("OptionA"/"OptionB"/"OptionC",1000) would return me "30". Even if I were to put an "OptionD" for the value, it would return "30" if the second number is under 5001.
Thus, it seems to only follow the second parameter --and thus only the second--even when closed off and is supposed to be not accessible to the first.
I am new to Script editor but do have modest Java experience (it'd work were this Java..) Could someone offer any advice/fixes? Any is appreciated. Thanks.
function getValcharge (valType, valAmount) {
var valcost =0;
if(valType="OptionA"){
if(valAmount < 5001)
{valcost = 76;}
if(valAmount > 5000 && valAmount <10001)
{valcost = 113;}
}
if(valType="OptionB"){
if(valAmount < 5001)
{valcost=43; }
if(valAmount > 5000 && valAmount <10001)
{valcost = 70;}
}
if(valType="OptionC")
{
if(valAmount < 5001)
{ valcost = 30; }
if(valAmount > 5000 && valAmount <10001)
{ valcost = 46; }
}
return valcost;
}
In Javascript you need to use a double-equals sign to test for equivalence, eg:
if(valType=="OptionA"){

Problems with conditional statement in jQuery

I'm having a problem handling some numbers from a json request. Based on the results I'm trying to output some various bits of HTML. Specifically the problem is when I come to check whether a number is greater than -1, but less than 6. Code excerpt is as follows…
else if(parseInt(myvariable, 10) < -1) {
//this is where one thing happens
}
else if(parseInt(myvariable, 10) > -1) {
//Something else happens here
}
else if(parseInt(myvariable, 10) > 6) {
//This is where the third thing should happen, but doesn't?
}
It seems that despite the value being 7 or 70 the second 'else if' is as far as it gets.
Is there a way that I can check that the number is more than -1 but less than 6 so that it moves on to the next conditional statement.
I'm guessing that (like my previous question) there's a very simple answer so please excuse my naivety.
Thanks in advance.
Conditions are executed only until one is found to be true.
In other words, you need to re-jig their order or tighten them to make your current order work.
7 is above -1, so the second condition resolves to true. So for 7, the 3rd condition is never needed.
if(parseInt(myvariable, 10) < -1) {
//number is less than -1
}
else if(parseInt(myvariable, 10) > 6) {
//number is above 6
}
else {
//neither, so must be inbetween -1 an 6
}
The if condition is wrong. Let's think of this: myvariable is 7.
In your code will happen:
else if(parseInt(myvariable, 10) < -1) {
//this is where one thing happens
}
else if(parseInt(myvariable, 10) > -1) {
**// HERE THE CONDITION IS TRUE, BECAUSE 7 > -1**
}
else if(parseInt(myvariable, 10) > 6) {
// This is where the third thing should happen, but doesn't?
}
You can change it as
else if(parseInt(myvariable, 10) < -1) {
//this is where one thing happens
}
else if(parseInt(myvariable, 10) > 6) {
// This is where the third thing should happen, but doesn't?
}
else if(parseInt(myvariable, 10) > -1) {
// Moved
}
To make it work...
Another solution is to change the second line:
else if(parseInt(myvariable, 10) > -1)
to:
else if(parseInt(myvariable, 10) <= 6)
There are so many ways of writing this.
yes because any number you will write greater than -1 will never go throw the third block of code , it will go throw the second, as you said "the number is more than -1 but less than 6" you can simply do like this :
else if(parseInt(myvariable, 10) < -1) {
//this is where one thing happens
}
else if(parseInt(myvariable, 10) > -1 && parseInt(myvariable, 10) < 6) {
//Something else happens here
}
I guess you can do this easily do something like this:
considering your variable value is (7):
else if(parseInt(myVariable, 10) < -1) {
//this is where one thing happens
}
else if(parseInt(myVariable, 10) > -1) {
//now 'myVariable' is greater than -1, then let's check if it is greater than 6
if(parseInt(myVariable, 10) > 6) {
//this where what you should do if 'myVariable' greater than -1 AND greater than 6
}
}

Switch statements and ranges of numbers

How do you craft a switch statement in as3 to make the case apply to an entire range of numbers?
if (mcPaddle.visible == true)
{
switch (score)
{
case 10://10 to 100
myColor.color = 0x111111;
break;
case 110://110 to 1000
//etc etc
break;
}
}
I've tried multiple ways to make the case apply for all numbers between 10-100, and 110-1000, but can't seem to find a way to do it, and I can't find the proper syntax for such a thing in as3.
You can use a switch block :
var score:Number = 123;
switch(true){
case score > 120 && score < 125 :
trace('score > 120 && score < 125');
break;
case score > 100 && score < 140 :
trace('score > 100 && score < 140');
break;
case score == 123 :
trace('score == 123');
break;
}
//score > 120 && score < 125
switch statements just restatements of if (a = b) or (a = c) or (a = d) ... type constructs. THey're not intended for ranges. You can somewhat simulate it using fallthroughs:
switch (score) {
case 10:
case 11:
case 12:
case 13:
case etc...
blah blah blah
break;
}
but that's a ludicrously dumb way to go. Much easier/terser to use a regular if()
ActionScript's switch statement doesn't work with ranges, but you can easily do it with if/else chains:
if (score >= 10 && score <= 100)
{
//10 - 100
}
else if (score <= 110)
{
//101 - 110
}
else if (score <= 1000)
{
//111 - 1000
}
For those looking for how to use this in HTML/jQuery, I've used #OXMO456's answer to create this simple pen: http://codepen.io/anon/pen/jHFoB
You just have to set the var normally and remove the lines starting with trace.
Ps. I'm adding this as an answer since I don't have enough rep to comment on his. If anyone can, please move/copy this there. Thanks!