I have this assessment test I have been working on for my job. I don't mess with JavaScript or SQL very often, but they want me to finish it anyway :/
Was wondering if anyone here, like my good buddy Monkeyfiend, has any experience with it. I'm more of an OOP C# programmer. It looks simple enough, but I'm stuck on the second set of JavaScript questions and the second two SQL questions. I put answers, but I want to be sure they are correct before sending it back Monday morning. I'll just post them here for anyone who wants to give it a shot. Very much appreciated for any assistance.
//JavaScript
let data = ["A","B","C"];
let results = ["1","2","3"];
let entity = {};
for(let i = 0; i < data.length; i++){
entity[data[i]] = results[i];
}
console.log(entity);
Question: What do you expect the console.log will output?
--------------------------------------------------------------------------------------------
let fs = require('fs');
function read() {
var promise = new Promise(function(resolve, reject) {
fs.readFile("myFile.txt", "utf8", (err, data) => {
if (!err) {
resolve(data);
}
else {
reject(err);
}
});
});
return promise;
}
Question: Use the read function and output the results.
read().then((x) => {console.log(x)}).catch((err) => console.log(err) );
----------------------------------------------------------------------------
async / await option
try{
const x = await read();
console.log(x);
}catch(err){
console.log(err);
}
-------------------------------------------------------------------------------
function getText(text){
return new Promise(function(resolve, reject){
setTimeout(function(){
if(text)
resolve(text);
else
reject(new Error("text is empty"))
}, Math.random() * 10);
});
}
function logData(data){
console.log(data);
}
getText("Hello").then(logData);
getText("World").then(logData);
Question: Sometimes this app produces “Hello World” sometimes it produces “World Hello”. Explain why and correct it.
----------------------------------------------------------------------------------------------------------------------------------------
function data (){
return [1,2];
}
let [x,y] = data();
console.log(x);
console.log(y);
Question: What will console log out in this program and why?
________________________________________
_______________
SQL Technical Screening
Books
Id (int)
Title (text)
Price (int)
Authors
Id (int)
Name (text)
BookAuthors
BookId (int)
AuthorId (int)
WRITE A SELECT STATEMENT SHOWING ALL THE BOOKS ORDERED BY TITLE IN ASCENDING ORDER
WRITE A SELECT STATEMENT SHOWING ALL THE BOOKS AND THE BOOK'S RELATED AUTHOR(S)
WRITE A SELECT STATEMENT SHOWING THE AVERAGE COST OF A BOOK BY AUTHOR
I almost have all the SQL completed, which seems simple, but the last one I am having a problem with. I'm getting the average of all the prices instead of just the average price of the books by a certain author. Here is what I have wrote:
Select Authors.Name, AVG(Price) AS AVG_Price
From Authors, BookAuthors
INNER JOIN Books ON BookAuthors.BookID = Books.ID
GROUP BY Authors.name;
I think I got it
Select Authors.Name, AVG(Price) AS AVG_Price
From Authors INNER JOIN BookAuthors ON BookAuthors.AuthorID = Authors.ID
INNER JOIN Books ON BookAuthors.BookID = Books.ID
GROUP BY Authors.name;
That seems to work.
Now, The only part on the Javascript I'm having seems to trouble everyone I've talked to. This is what they gave me:
let fs = require('fs');
function read() {
var promise = new Promise(function(resolve, reject) {
fs.readFile("myFile.txt", "utf8", (err, data) => {
if (!err) {
resolve(data);
}
else {
reject(err);
}
});
});
return promise;
}
------------------------------------------------------------------------------
Question: Use the read function and output the results.
read().then((x) => {console.log(x)}).catch((err) => console.log(err) );
--------------------------------------------------------------------------------
async / await option
try{
const x = await read();
console.log(x);
}catch(err){
console.log(err);
}
-----------------------------------------------------------------------------------
That is what they gave me. I didn't put any answer yet. I'm not sure what to do with this. It's almost like they gave me the problem and the answer, and there is nothing left to do. Am I missing something here?
My JavaScript-fu is quite weak. I saved the program along with the first answer in t.js and ran it with node t.js.
This produced the following error:
I appreciate your time for looking into this Sir Robin! I just sent it back to them and said I believe something is missing, like the file to read from. They said that one of the developers made the assessment test, and that there could be something missing. I guess we'll find out sometime this week
Hey fido. How did it go?
Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)