0

ColdFusion Test

ColdFusion, test

Here is a ColdFusion test that I found see how you do.

1. Which of these are NOT legal variable names?
a. $myVar
b. my-Var
c. _true
d. my$Var
e. false

2. What will this code produce?

<cfset test = RandRange(0, 1)>
<cfif NOT test>
    <cfset x = Val(100/test)>
<cfelse>
    <cfset x = Val(100/(test*0))>
</cfif>


3. Write code to output 1 to 1000, comma-delimited, (stepping by 1) without using the tag (e.g., 1,2,3,4,5… etc):

4. List as many ColdFusion application scopes as possible and explain each briefly.

5. Given a query “myQuery”, how would you get the column names that are returned by this query?

15. Given a query “myQuery”, how would you find out the total records returned by this query?


6. This is a query returned called “myQuery”:
Row Name Company
1 Jeff widget1
2 David Solisys
3 Darryl Adobe
4 Jim widget1
5 Marie Adobe

Write code to return the following output given the query above:
widget1
Jeff
Jim
Solisys
David
Adobe
Darryl
Marie

7. Given a query, "Products", with the fields: "id", "price", and "description", how can you output the price of the LAST row in the query without using either a loop or another query?

8. Given a custom tag, "ListNoDupes", that accepts the variables: "list" and "returnAs". The last line of the tag is this:

<cfset SetVariable('caller.' & attributes.returnAs, newList) />


What will happen on the page that calls this custom tag?
a. Nothing
b. A variable called "caller.returnAs" will be set as a local variable on the calling page
c. A request-scoped variable called "newList" will be created
d. A local variable will be set on the calling page with the same name as the value of the "returnAs" parameter passed into the custom tag.
e. If no variable called "returnAs" exists on the calling page, it will be created. If such a variable does exist, nothing will happen.

9. Given this CFC:

<cfcomponent displayname="Classroom">
    <cfset variables.students = ArrayNew() />
    <cfset variables.teacher = "" />

    <cffunction name="addStudent" returntype="void">
		<cfargument name="student" type="Student" required="true">
		<cfset ArrayAppend(getStudents(), arguments.student) />
    </cffunction>

    <cffunction name="getStudents" returntype="array">
		<cfreturn variables.students />
    </cffunction>
</cfcomponent>


You create 1 "Classroom" object, "classroom", and 3 Student objects. You call the "addStudent()" method, passing in each of the three new students. At the end of this, what will this code produce?
#ArrayLen(classroom.getStudents())#

10. You've been given a text file, "CityTemperatures.txt". Each line in the file contains the temperatures for each day in the same week for different cities.
Atlanta: 54,57,52,34,45,49,53
Baltimore: 67,72,69,77,79,71,74
Chicago: 81,72,79,74,76,67,72
Denver: 68,64,75,69,72,63,68
Can you read and display the low, high, and average temperatures for each city in 10 lines of code or less?



11. You have a query, "Products", with the following columns: "id", "price", "description", and "quantityOnHand". You need to create a form with a checkbox for each row in the Products query, all using the name, "selectedProducts". The problem is that you need to send information about both the id of the product chosen AND the quantity on hand. At first, you think of putting a hidden form field for each query row that would contain this info, but your co-worker casually remarks that she always does this without using any more form inputs than there are rows. What's her secret?




12. Look at this code:
<cfset susie = StructNew() />
<cfset susie.employer = "ibm" />

<cfset me = StructNew() />
<cfset me.spouse = susie />

<cfset me.spouse.employer = "self-employed" />

What's the value of susie.employer?

13. You've produced a two-dimensional array, "arr", that you need to save as a client variable. What's the code for this?


14. Explain this code:

<cfdirectory action="list" directory="#ExpandPath('./images/mainpic/#ATTRIBUTES.MainPicDir#')#" sort="ASC" name="ImageList" filter="*.*">

<cfif ImageList.recordcount eq 1>

    <cfoutput query="ImageList">
        <img src="./images/mainpic/#ATTRIBUTES.MainPicDir#/#ImageList.name />
    </cfoutput>

<cfelseif ImageList.recordcount>

    <cfset randImageNum = randrange(1,#ImageList.recordcount#)>
    <cfoutput query="ImageList" startrow="#randImageNum#" maxrows="1">
        <img src="./images/mainpic/#ATTRIBUTES.MainPicDir#/#ImageList.name#" />
    </cfoutput>   

</cfif>


15. In the previous code, what is does ATTRIBUTES.MainPicDir stand for? What does the ATTRIBUTES scope for this variable mean?

 
Interesting. Some of these had me thinking.
 
posted 604 days ago
Add Comment Reply to: this comment OR this thread
 

Search

Matt  Graf
View Matt Graf's profile on LinkedIn