IPB





Welcome Guest ( Log In | Register )

> Need some help from Javascript and SQL peeps, I have an assesment test I have been working on
fido77
post Oct 31 2021, 10:08 PM
Post #1


Knight Lieutenant
********

Group: Clan Members
Posts: 989
Thank(s): 1
Joined: 5-June 08
From: Tyler, Texas, US
Member No.: 124




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




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

Go to the top of the page
 
+Quote Post
 
Start new topic
Replies
fido77
post Nov 1 2021, 04:28 AM
Post #2


Knight Lieutenant
********

Group: Clan Members
Posts: 989
Thank(s): 1
Joined: 5-June 08
From: Tyler, Texas, US
Member No.: 124




I think I got it smile.gif

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?


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

Go to the top of the page
 
+Quote Post

Posts in this topic


Reply to this topicStart new topic

 



RSS Lo-Fi Version Time is now: 11th October 2025 - 10:17 PM
Sneaky Monkeys Clan :: MonkeyFiend.com