Click to See Complete Forum and Search --> : Combining Scripts for beginner


krismisz
01-22-2003, 05:36 PM
I was wondering if anyone could please help me. I am a beginner and I found two great scripts at Javascript.internet.com that I would like to combine:

1. http://javascript.internet.com/miscellaneous/javascript-quiz.html

2. http://javascript.internet.com/miscellaneous/user-quiz.html

I like how the first quiz is set up, but I want to add the "advance to next level" feature of the second one. (If they get a certain number right, they advance to harder quiz). Is there an easy way to do this? Keep in mind I know practically nothing about Javascript!

I'd be so greatful for any help!
krismisz

jdavia
01-22-2003, 09:53 PM
You will see a line like this:

alert("Access permitted! But there are no more levels if you don't make any ...")
//change previous line to:self.location="js_misc_userquiz2.html" if you make more
Delete this whole line
alert("Access permitted! But there are no more levels if you don't make any ...")

Replace it with this one.
self.location="js_misc_userquiz2.html"

That's not all.
You saved the Quiz and named it already. You have to "Save As" again to "js_misc_userquiz2.html", that will be the advanced page.

Just make changes to the questions and answers for some new ones.

These are the answer tabs. Jugle the letters "A" "B" around for the new locations too.

ans[1] = "c";
ans[2] = "a";
ans[3] = "b";
ans[4] = "b";
ans[5] = "d";
ans[6] = "c";
ans[7] = "c";
ans[8] = "c";
ans[9] = "d";
ans[10] = "a";

Good Luck and have fun.

krismisz
01-22-2003, 10:28 PM
jdavia, will this let me keep the quiz in the same form as the first link and only move on if they have, say, 8 questions answered correctly?

krismisz

jdavia
01-23-2003, 12:44 AM
Yes it will look the same as what you downloaded.

They move on when 7 answers are correct, but you can change that to whatever amount you want. Just edit these three places in the code.

if (score >= 7 && score

Access denied! You need 7 points to enter the next level.

Objective: answer 7 questions correctly. JavaScript required!

krismisz
01-27-2003, 11:36 PM
Thanks so much for all of your help!

jmazur01
07-12-2004, 08:06 AM
hi there...
i've searched through the kbase / forums and found a ton of useful information, but i'm still stumped on this.

what i'm trying to do is combine these 2 scripts into one, that i link to externally

i keep my scripts in the /scripts folder and want to name the combined 2, default.js


Script 1:

code:--------------------------------------------------------------------------------

window.onload = init;

function init() {
if (window.ActiveXObject && document.body.innerHTML != "") {
oldBodyText = document.body.innerHTML;
reg = /<ABBR([^>]*)>(.*?)<\/ABBR>/gi;
newBodyText = oldBodyText.replace(reg,'<ABBR $1><SPAN class=\"abbr\" $1>$2</SPAN></ABBR>');
document.body.innerHTML = newBodyText;
}
}

--------------------------------------------------------------------------------



Script 2:

code:--------------------------------------------------------------------------------

function setActiveStyleSheet(title) {
var i, a, main;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
a.disabled = true;
if(a.getAttribute("title") == title) a.disabled = false;
}
}
}

function getActiveStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
}
return null;
}

function getPreferredStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1
&& a.getAttribute("rel").indexOf("alt") == -1
&& a.getAttribute("title")
) return a.getAttribute("title");
}
return null;
}

function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

window.onload = function(e) {
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
}

window.onunload = function(e) {
var title = getActiveStyleSheet();
createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

--------------------------------------------------------------------------------


any help would be greatly appreciated.
thank you so kindly.