How can i add numbers together that was extracted - imacros

I have an macros for addmefast, i extracting gained points and i want count them together.
For example first extract was "8" on the next iteration and extraction would be "4" so i want to add them together.
for(var i = 1; i <= total; i++) {
iimPlay(path+"Facebook Like.iim")
iimPlayCode('TAG POS=1 TYPE=DIV ATTR=CLASS:"success_like" EXTRACT=TXT\nSET !EXTRACT EVAL("\'{{!EXTRACT}}\'.match(/\\d+/)[0]")\n');
var gain = iimGetLastExtract();
iimDisplay('Gained Points : ' + points );
}

Try like so:
var gainTotal = 0;
for(var i = 1; i <= total; i++) {
iimPlay(path+"Facebook Like.iim")
iimPlayCode('TAG POS=1 TYPE=DIV ATTR=CLASS:"success_like" EXTRACT=TXT\nSET !EXTRACT EVAL("\'{{!EXTRACT}}\'.match(/\\d+/)[0]")\n');
var gain = parseInt(iimGetLastExtract());
gainTotal += gain;
iimDisplay('Gained Points : ' + points );
}
alert(gainTotal);

Related

Building a css grid with javascript: creating elements, storing them in arrays and append them to other elements

I recently build an masonry gallery with html and css. I used the display: grid; property to make it look like so. Now I am trying to create randomized layouts. Therefor I want to create elements with classes. I want to append / elements to the elements, store those elements inside an array and later append them inside my "masonry" . I put in different console.logs to see whats happening, but I get some either weird or undefined returns. Javascript can be as tricky as it can be fun for beginners, so I hope you guys can help me out.
Thank you all. :)
//arrays and variables
const figures = [];
let newFigures = "";
const divs = [];
let newDivs = "";
function makeCells(){
for(let i = 0; i < 33; i++){
newFigure = document.createElement("figure");
figures[i] = newFigure.classList.add("cell", "cell--" + i);
newDiv = document.createElement("div");
divs[i] = newDiv.setAttribute("id", i);
console.log("log1: " + newFigure.classList);
console.log("log2: " + figures[i]);
}
console.log("log3: " + divs);
console.log("log4: " + figures);
console.log("log5: " + divs);
for(let i=0; i<3; i++){
figures[i] = newFigure.appendChild(newDiv);
}
console.log("figures = " + figures);
console.log("divs = " + divs);
let z = {};
for(let i=0; i<3; i++){
z = figures[i];
document.getElementById("masonry").appendChild(z);
}
console.log(document.getElementById("masonry"));
}
Here is a picture of the corresponding console.logs.
Console Logs
This works as intended:
const figures = [];
let newFigure = "";
const divs = [];
let newDiv = "";
function makeCells(){
for(let i = 0; i < 33; i++){
newFigure = document.createElement("figure");
newDiv = document.createElement("div");
newFigure.appendChild(newDiv);
document.getElementById("masonry").appendChild(newFigure);
figures[i] = newFigure.classList.add("cell", "cell--" + i);
}
console.log(document.getElementById("masonry"));
}
Sorry to bother you guys.
I don't like this line of code, mainly because the add() method does not have a return value.
figures[i] = newFigure.classList.add("cell", "cell--" + i);
I would split it into two statements.
newFigure.classList.add("cell", "cell--" + i);
figures.push(newFigure);

Replace non-blank cells with 0

I tried to find solutions online however couldn't find one specifically for my need: I want to create a script which replaces non-blank cells in given column with 0.
Is there a simple solution for this?
Thanks.
Try:
function blankTo0() {
var ss=SpreadsheetApp.getActiveSpreadsheet()
var s = ss.getActiveSheet()
var rng = s.getRange("A:A");//change to column you want
var data= rng.getValues()
for (var i=0; i < data.length; i++) {
if (data[i][0] == "") {
data[i][0] = 0;
} else if (data[i][0] == "") {
data[i][0] = data[i][0];
}}
rng.setValues(data); // replace old data with new
}

Adding items to a Google Forms list from a spreadsheet range

I am struggling to get past the last line in this code any help will be appreciated:
The error I am getting is "Array is empty: values (line 16, file "Code")". I have double checked the item ID, the spreadsheet ID and that there is data for it to pick up within the correct range. Any pointers or insights...?
function GetFleet() {
var ssDEFECTS = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var rngFLEET = ssDEFECTS.getDataRange();
var values = rngFLEET.getValues();
var FleetList = [];
//Use column 0 and ignore row 1 (headers)
for (var i = 1; i <= values.length; i++) {
var v = values[i] && values[i][0];
v && values.push(v)
}
// Form ID & List ID
var DefectsForm = FormApp.openById('<FORM KEY ID>');
DefectsForm.getItemById(794194842).asListItem().setChoiceValues(FleetList);
};
Nothing is pushed to your array FleetList. Also the coding in your loop is faulty.
Assuming you want to push the first column (not including the header),
try this and see if it works
function GetFleet() {
var values = SpreadsheetApp.getActiveSpreadsheet()
.getSheets()[0].getDataRange()
.getValues();
var FleetList = [];
//Use column 0 and ignore row 1 (headers)
for (var i = 1, len = values.length; i < len; i++) {
FleetList.push(values[i][0])
}
// Form ID & List ID
var DefectsForm = FormApp.openById('<FORM KEY ID>');
DefectsForm.getItemById(794194842)
.asListItem()
.setChoiceValues(FleetList);
};

Sidebar to show currently displayed markers - combined IF statement

I would really appreciate some help with this problem. It may be easy to solve but I just can't figure out how to go about coding it. I have a map based on this Geocodezip Example Categories which displays markers and has a sidebar next to it. The markers belong to one of three categories and based on whether the checkboxes are checked, the markers will appear on the map.
function show(category) {
for (var i=0; i<gmarkers.length; i++) {
if (gmarkers[i].mycategory == category) {
gmarkers[i].setVisible(true);
}
}
document.getElementById(category+"box").checked = true;
}
function hide(category) {
for (var i=0; i<gmarkers.length; i++) {
if (gmarkers[i].mycategory == category) {
gmarkers[i].setVisible(false);
}
}
document.getElementById(category+"box").checked = false;
infowindow.close();
}
At the same time, I am trying to display the markers' info in the sidebar but under two conditions:
the marker category must be checked &
the marker must be contained in the map viewport/bounds
I then added one code for the sidebar that only displays the markers for checked categories and one where the info is shown in the sidebar when the markers are in the viewport. However, I can only do these separately (for to completely different codes) and cannot get both conditions to work together. These are the two examples that I am trying to merge:
Include in sidebar if box is checked
function makeSidebar() {
var side_bar_html = "";
for (var i=0; i<gmarkers.length; i++) {
if (gmarkers[i].getVisible()) {
side_bar_html += '<a href="javascript:myclick(' + i + ')">' + gmarkers[i].myname + '<\/a><br>';
}
}
document.getElementById("side_bar").innerHTML = side_bar_html;
}
(when bounds change) Include in sidebar if marker is contained within bounds
function makeSidebar() {
google.maps.event.addListener(map, 'bounds_changed', function() {
var side_bar_html = "";
var bounds = map.getBounds();
for (var i=0; i<gmarkers.length; i++) {
if (bounds.contains(gmarkers[i].position)) {
side_bar_html += '<a href="javascript:myclick(' + i + ')">' + gmarkers[i].myname + '<\/a><br>';
}
}
document.getElementById("side_bar").innerHTML = side_bar_html;
});
}
I tried putting the two together in a combined if statement (&&) within the if bounds.contains statement but the sidebar won't change if a box is checked/unchecked.
Add the check to makeSidebar only when the map bounds is available:
// == rebuilds the sidebar to match the markers currently displayed ==
function makeSidebar() {
var html = "";
for (var i=0; i<gmarkers.length; i++) {
if (gmarkers[i].getVisible() &&
map.getBounds &&
map.getBounds() &&
map.getBounds().contains(gmarkers[i].getPosition())) {
html += '<a href="javascript:myclick(' + i + ')">' + gmarkers[i].myname + '<\/a><br>';
}
}
document.getElementById("side_bar").innerHTML = html;
}
execute makeSidebar when the bounds_changed event fires:
google.maps.event.addListener(map, 'bounds_changed', makeSidebar);
working fiddle

Flex 3 - how to select an item in the list as default?

how to select an item in the list as default
default selected item say of index 0
I tried stuff like this --
listid.selectedIndex = somevalueinmyprogram - 1; // 0
but when i debug this i get
_selectedIndex = 0
selectedIndex = -1
and default value is not selected why so?
[i have already checked for the obvious that somevaluefrommyprogram is not equal to 0]
Help!
I have found that if you set the selectedItems by defining an array of selected items it works better than the selectedIndex.
function setSelectedCategories():void{
var selectedItems :Array = new Array();
for each (var selectedCategory:Category in entry.categories) {
for each (var category:Category in categories) {
if (selectedCategory.categoryID == category.categoryID){
selectedItems .push(category);
break;
}
}
}
categoriesList.selectedItems = selectedItems ;
}
OR using the selectedIndices works if you want to use an array that contains the indexes that you want to be selected.
for ( var i:int=0; i < userIpods.length; i++ ) {
//j will represent the list item's index value
for ( var j:int = 0; j < iPodAry.length; j++) {
if ( userIpods[i] == iPodAry[j].id ) {
selectedIpodIndices.push( j );
break;
} //end if
} //end for ( var iPodObj:Object in iPodAry) {
} //end for ( var i:int in userIpods )
/*mark as selected those index values in the
selectedIpodIndices array*/
iPodList.selectedIndices = selectedIpodIndices ;