# Load external text files into variable

**URL:** <https://forum.kirupa.com/t/load-external-text-files-into-variable/150799>\
**Category:** Uncategorized\
**Created:** [June 10, 2005, 1:55pm UTC](https://forum.kirupa.com/t/load-external-text-files-into-variable/150799 "2005-06-10T13:55:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kwpang1](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@kwpang1](https://forum.kirupa.com/u/kwpang1)\
**Post date:** [June 10, 2005, 1:55pm UTC](https://forum.kirupa.com/t/load-external-text-files-into-variable/150799/1 "2005-06-10T13:55:00Z")

</div>

loadText = new LoadVars();  
\> i = int(Math.random()\*20+1);  
\> loadText.load(i+".txt");  
\> j = 0;  
\> //creating the loadVarsText function  
\> loadText.onLoad = function() {  
\> scroller.htmlText = this.myText;  
\> j = this.answer;  
\> };  
\>  
\> this code will load random questions (named q1.txt - q20.txt) into the text  
area. the questions are identified by the variable “myText”. also in the text  
files are the answers. the answers are identified by the variable “answers”. a  
sample of the text file q1.txt is as below:  
\> myText=  
\> \<font face=“Verdana” size=“10” color="#FF0000"\>  
\> \<b\>Digestion\</b\>\</font\>\<font face=“Verdana” size=“10”\>  
\> Which of the following are enzymes found in the stomach? \<br\> 1) Amylase  
2) Maltase \<br\> 3) Pepsin 4) Sucrase\</font\>  
\> answer=3  
\>  
\> i am able to successfully load myText into the text area. however, i am not  
able to assign the variable “answer” to the local variable “j”. (which i will  
use later on for quiz answer checking).  
\> is there anyway i am able to load the answer into variable j?  
\> can you please correct me if i am wrong in this comparison of string:  
\> if (j===“1”) {  
\> (play animation for correct answer)
