Creating A Worksheet Generator - html

I hope you are having a great day!
I have an ecommerce website with pdfs and ebooks for sale. We are based on "education" and we have seen a few websites that have worksheet generators. We tried using httrack to see how they made the script but nothing worked. We would love some help in how does it work and are there any tutorials for that type of task. Thanks and have a great day!
Edit: We forgot to say, we want something similar to education.com

I think this code useful for you....
code.
<html>
<head>
<title>Math WorkSheet</title>
<script type="text/javascript">
// For: http://codingforums.com/showthread.php?t=184125
var NProblems = 25;
var xvals = [];
var yvals = [];
for (var i = 0; i < NProblems; i++) {
// xvals.push(i); yvals.push(i+1); // limit to problem values to (0,1) ... 25
xvals.push(i % 10);
yvals.push((i % 10) + 1); // limit to single digit problems
}
function MakeTable(act) {
var tmp = '';
var str = '<table border="1" width="80%"><tr>';
i = 0;
while (i < NProblems) {
x = xvals[i];
y = yvals[i];
str += '<td align="right">' + x;
if (act == 'add') {
str += '<br>+ ' + y;
tmp = x + y;
}
if (act == 'sub') {
str += '<br>- ' + y;
tmp = x - y;
}
if (act == 'mul') {
str += '<br>* ' + y;
tmp = x * y;
}
if (act == 'div') {
str += '<br>/ ' + y;
tmp = (x / y).toFixed(2);
}
str += '<br>_____';
if (document.getElementById('answers').checked) {
str += '<br>' + tmp;
} else {
str += '<br> '
}
str += '<br> </td>';
i++;
if ((i % 5) == 0) {
str += '</tr><tr>';
}
}
str += '</tr></table>';
return str;
}
function GenerateWS() {
var x = 0;
var y = 0;
var str = '';
var str = '';
var sel = document.getElementById('MathAction').value;
switch (sel) {
case 'add':
str += MakeTable(sel);
break;
case 'sub':
str += MakeTable(sel);
break;
case 'mul':
str += MakeTable(sel);
break;
case 'div':
str += MakeTable(sel);
break;
default:
alert('No choice selected');
break;
}
document.getElementById('TBL').innerHTML = str;
}
function randOrd() {
return (Math.round(Math.random()) - 0.5);
}
function NewSet() {
xvals.sort(randOrd);
yvals.sort(randOrd);
}
</script>
</head>
<body>
<select id="MathAction">
<option value="add">Addition</option>
<option value="sub">Subtraction</option>
<option value="mul">Multiplication</option>
<option value="div">Division</option>
</select>
<button onclick="NewSet()">New worksheet</button>
<input type="checkbox" id="answers">Show Answers
<button onclick="GenerateWS()">Generate Worksheet</button>
<div id="TBL"></div>
</body>
</html>

Related

How to find the latitude and longitude of the beginning and the end of a street?

I'm trying to find the coordinates (LAT LONG) of a street from the beginning to the end of the street with the GOOGLE MAPS API. I can not find some simillaria on the net
Thanks
I use this code :
function findEndAddr(addr) {
for (var i = 500;;) {
var Http = new XMLHttpRequest();
var url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + i.toString().split('.')[0] + addr.replace(/\s/g, '') + '&key=KEY_API';
console.log(url);
Http.open("GET", url, false);
Http.send(null);
if (Http.status == 200 && Http.readyState == 4) {
var resp = JSON.parse(Http.responseText);
if (resp['results'][0]['address_components'][0]['types'][0] != 'street_number') {
i = i / 2;
}
else {
return findEndAddrNext(addr, i, i, 2);
}
}
}
}
And I use this function :
function findEndAddrNext(addr, i, nb, div) {
var Http = new XMLHttpRequest();
var url;
url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + nb.toString().split('.')[0] + addr.replace(/\s/g, '') + '&key=KEY-API';
console.log(url);
Http.open("GET", url, false);
Http.send(null);
if (Http.status == 200 && Http.readyState == 4) {
var resp = JSON.parse(Http.responseText);
var index = 0;
for (let cpt = 0; cpt < resp['results'].length; cpt++) {
console.log(getThing(resp['results'][cpt]['address_components'], 'postal_code'));
console.log(addr.split(',')[2]);
if (getThing(resp['results'][cpt]['address_components'], 'locality') == addr.split(',')[1]) {
index = cpt;
break;
}
}
if (resp['results'][index]['address_components'][0]['types'][0] == 'street_number') {
i = nb;
if ((nb / div) <= 2) {
if (getThing(resp['results'][index]['address_components'], 'locality') != addr.split(',')[1]) {
oui = searchFinal(getThing(resp['results'][index]['address_components'], 'street_number'), addr);
return;
}
oui = [resp['results'][index]['geometry']['location'].lat, resp['results'][0]['geometry']['location'].lng];
console.log(resp);
return;
}
nb = nb + (nb / div);
findEndAddrNext(addr, i, nb, div);
}
if (resp['results'][index]['address_components'][0]['types'][0] != 'street_number') {
div *= 2;
nb = i + (i / div);
findEndAddrNext(addr, i, nb, div);
}
}
}

How can I properly write the following if statement with getLabel()

I'm getting the following error and would like to know how to rewrite this code properly.
ReferenceError: Function function getLabel() {/* */} can not be used as the left-hand side of assignment or as an operand of ++ or -- operator. (line 61, file "DLContactsToSheet")
var Phones = "";
for ( var g=0;g<contacts[i].getPhones().length;g++)
{
if (contacts[i].getPhones()[g].getLabel() = "MOBILE_PHONE") {
Phones += "C: "
} else if (contacts[i].getPhones()[g].getLabel() = "WORK_PHONE") {
Phones += "W: "
} else if (contacts[i].getPhones()[g].getLabel() = "HOME_PHONE") {
Phones += "H: "
} else {
Phones += "O: "
}
Phones += contacts[i].getPhones()[g].getPhoneNumber();
Phones += "\n";
}
try{ContactArray.push(Phones);}
catch(e){ContactArray.push("N/A")}
It would appear that the reference error is caused by an '=' rather than an '==' in your conditions.
Rewriting the conditions as if (phone.getLabel() == 'MOBILE_PHONE') { /* ... */ } etc should do the trick.
You need to hard code them, in order to fetch them.
Code
function fieldType() {
var contacts = ContactsApp.getContacts(), phones = [];
for(var i = 0, iLen = contacts.length; i < iLen; i++) {
var con = contacts[i], f = ContactsApp.Field;
var c = con.getPhones(f.MOBILE_PHONE), w = con.getPhones(f.HOME_PHONE), h = con.getPhones(f.WORK_PHONE);
phones = getNumber(phones, c, "C: ");
phones = getNumber(phones, w, "W: ");
phones = getNumber(phones, h, "H: ");
}
}
function getNumber(phones, type, prefix) {
var typeNumbers = [];
var pNumber = type.length > 0 ? type.map( function (d) { return prefix + d.getPhoneNumber() + "\n"; }) : null;
if(pNumber) {
typeNumbers.push(pNumber);
}
return phones.concat(typeNumbers);
}
Note
See method description for more info: getPhoneNumber()
You should probably store the value for each iteration in a variable before any conditional statements. A case-switch statement is probably also better suited for this.
for ( var g=0;g<contacts[i].getPhones().length;g++)
{
var phone_type = contacts[i].getPhones()[g].getLabel()
switch(phone_type) {
case "MOBILE_PHONE":
Phones += "C: "
break;
case "WORK_PHONE":
Phones += "W: "
break;
case "HOME_PHONE":
Phones += "H: "
break;
default:
Phones += "O: "
}
Phones += contacts[i].getPhones()[g].getPhoneNumber();
Phones += "\n";
}

Issue with a zero showing after a decimal point

I have a script set up to extract figures from a csv file into a webpage. We have a problem in that a figure that have a 0 after the decimal point is being ignored so whilst the csv file shows 1.094 when teh figure is transferred to the webpage it is 1.94
There is a js script and then an asp script that works the function
function getHTTPObject()
{
var x = null;
if (window.XMLHttpRequest)
{
x = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
x = new ActiveXObject("Microsoft.XMLHTTP");
if (!x)
{
x = new ActiveXObject("Msxml2.XMLHTTP");
}
}
return x;
}
var gobj = getHTTPObject();
window.onload=update();
function update()
{
var xpath = "ratesxtract.asp";
if (gobj) {
gobj.open("GET", xpath, true);
gobj.onreadystatechange = update_all;
gobj.send(null);
}
else {alert("XMLHTTP access problem. Please exit page and try again" ); }
}
function update_all()
{
if (gobj.readyState == 4) {
if (gobj.status == 200) {
// dobj = document.getElementById("BLastUpdated");
var A = gobj.responseText;
// dobj.innerHTML = A;
if (A == "error") {alert("XMLHTTP access problem. Please exit page and contact us" ); }
else { processfile(A); }
}
}
function processfile(A)
{
var errormess = "none";
var AA = new String(A);
AA = AA.split("$");
var nName = null;
var dobj = null;
var nValue = null;
var i = 0;
for (i = 0; i < AA.length; i++) {
if (AA[i].charAt(0) == "Z") {
nName = AA[i];
dobj = document.getElementById(nName);
}
else { nValue = "";
nValue += AA[i];
dobj.innerHTML = nValue;
}
}
if ( i == 0 ) { errormess = "failed to access exchange rates data, please exit page and try again";
alert(errormess)
}
}
ASP SCRIPT
<%#LANGUAGE='JScript'%>
<%
var sfile = Server.MapPath("forex\\ratefile.csv");
var fs = Server.CreateObject("Scripting.FileSystemObject");
var fsT = fs.OpenTextFile(sfile, 1, 0);
var xline;
var p = 0;
var q = 0;
var d = 0;
var i = 0;
var n = 0;
var t = 0;
var ts = 0;
var mname;
var mprice;
var mtime = "";
var INLine
var LN;
var cresult = "";
while(!fsT.AtEndOfStream) {
INLine = fsT.ReadLine();
xline = String(INLine);
if ( p != 0) {
LN = xline.split(",");
mname = xtrim(LN[0]);
mprice = doamount3(LN[1]);
if (p == 1) { mtime = xtrim(LN[2]); }
if (n > 0){ cresult += "$"; }
n++;
cresult += "Z" + mname + "$" + mprice;
}
p++;
}
cresult += "$ZTIM$" + mtime;
fsT.Close();
Response.Write(cresult);
%>
<%
function xtrim(x)
{
var xd = x.replace(/^\s+|\s+$/gm,'');
return xd;
}
function doamount3(amt)
{
var ZLine = String(amt);
ZLine = xtrim(ZLine);
if (ZLine.indexOf(".") == -1) {
ZLine += ".00";
return(ZLine);
}
var idata = ZLine.split(".");
var xadp = new String(idata[1]);
var xlen = xadp.length;
if (xlen == 1) {
idata[1] = xadp + "00";
ZLine = idata[0] + "." + idata[1];
return(ZLine);
}
if (xlen == 2) {
idata[1] = xadp + "0";
ZLine = idata[0] + "." + idata[1];
return(ZLine);
}
var p4 = xadp.charAt(3);
var p3 = parseInt(xadp.substring(0,3), 10);
if (p4 > 4) { p3 += 0; }
idata[1] = String(p3);
ZLine = idata[0] + "." + idata[1];
return(ZLine);
}
%>
If anyone can help be greatly appreciated

Get total rows filtered by if() statement in google apps scripts

I've got this fn().
Is there any simple way to return the number of filtered rows by this conditional statement in Google app scripts?
function getGlobers(globers, project){
var body = "";
var data = globers.getValues();
for( i = 0; i < data.length; i++ ){
if( data[i][2] == project ){
body += "<tr><td style=" + STYLE.TD + ">" + data[i].join("</td><td style=" + STYLE.TD + ">") + "</td></tr>";
}
}
return body;
}
Thanks.
for example (see comments in code)
function getGlobers(globers, project){
var body = "";
var n = 0; // use a variable to count
var data = globers.getValues();
for( i = 0; i < data.length; i++ ){
if( data[i][2] == project ){
n++;// increment each time condition is true
body += "<tr><td style=" + STYLE.TD + ">" + data[i].join("</td><td style=" + STYLE.TD + ">") + "</td></tr>";
}
}
return [body,n];// return an array of 2 values
}
Usage :
var result = getGlobers(range,project);
Logger.log('array result = '+result);
Logger.log('body (string) = '+result[0]);
Logger.log('length (integer) = '+result[1]);
note : instead of an array you could also return an object with 2 properties... a matter of choice.
EDIT : an example using object properties :
function getGlobers(globers, project){
var body = "";
var n = 0;
var result = {};
var data = globers.getValues();
for( i = 0; i < data.length; i++ ){
if( data[i][2] == project ){
n++;
body += "<tr><td style=" + STYLE.TD + ">" + data[i].join("</td><td style=" + STYLE.TD + ">") + "</td></tr>";
}
}
result['body'] = body;
result['length'] = n;
return result;
}
Usage :
var result = getGlobers(range,project);
Logger.log('body = '+result.body);
Logger.log('length = '+result.length);

jQuery click() each() unique?

I want to have multiple span.play without IDs which can be clicked and play some audio file.
Problem: Display the duration on only the current file $(this)
$('.play').each(function() {
$(this).append('<span class="playIcon"><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/7/76/Fairytale_player_play.png/14px-Fairytale_player_play.png"></span><span class="playDur"></span>');
$(this).click(function() {
var file = this.firstChild;
if (file.paused != false) {
//+ stop all others before playing new one
file.play();
} else {
file.pause();
}
file.addEventListener("timeupdate", function() {
var len = file.duration,
ct = file.currentTime,
s = parseInt(ct % 60),
m = parseInt((ct / 60) % 60);
if (s < 10) {
s = '0' + s;
}
$(".playDur").html(' (' + m + ':' + s + ')');
if (ct == len) {
$(".playDur").html('');
}
}, false);
});
});
Test:
http://jsfiddle.net/sQPPP/
http://jsfiddle.net/sQPPP/1/ - using $(this).children( ".foo" )
You need to save .play jQuery object in a variable, as this changes within the addEventListener callback.
http://jsfiddle.net/sQPPP/2/
$('.play').each(function(index) {
var $play = $(this);
$play.append('<span class="playIcon"><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/7/76/Fairytale_player_play.png/14px-Fairytale_player_play.png"></span><span class="playDur"></span>');
$play.click(function() {
var file = this.firstChild;
if (file.paused != false) {
//+ stop all others before playing new one
file.play();
} else {
file.pause();
}
file.addEventListener("timeupdate", function() {
var len = file.duration,
ct = file.currentTime,
s = parseInt(ct % 60),
m = parseInt((ct / 60) % 60);
if (s < 10) {
s = '0' + s;
}
$play.children( ".playDur" ).html(' (' + m + ':' + s + ')');
if (ct == len) {
$play.children( ".playDur" ).html('');
}
}, false);
});
});​