Skip to content

Commit 5852fb4

Browse files
committed
make answerUrl a global variable
1 parent 2a078cf commit 5852fb4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

scripts/app.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
document.addEventListener("DOMContentLoaded", function(){
1+
2+
const answerUrl = baseUrl+'questions/answers';
3+
4+
document.addEventListener("DOMContentLoaded", function(){
25

36
fetch(baseUrl+'questions/recent').then(response => {
47
return response.json();
@@ -46,20 +49,17 @@ function saveAnswer(questionId) {
4649
questionId = findDom('featured-question-id').value;
4750
const userId = findDom('featured-question-user-id').value;
4851
const answer = findDom('answer-body').value;
49-
const answerUrl = baseUrl+'questions/answers';
5052
const queryBody = 'question_id='+questionId+'&user_id='+userId+'&answer='+answer;
5153
//check if valid characters are entered in answer text
5254
if (typeof answer === "string" && answer.trim().length >= 5) {
5355
fetch(answerUrl,
5456
{
5557
method: 'post',
5658
headers: {
57-
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8",
58-
"authorization": localStorage.Authorization
59+
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8","authorization": localStorage.Authorization
5960
},
6061
body: queryBody
61-
})
62-
.then(response => {
62+
}).then(response => {
6363
return response.json();
6464
}).then(data => {
6565
if (data['status'] === 200) {
@@ -69,12 +69,12 @@ fetch(answerUrl,
6969
}
7070
}).catch(err => {
7171
console.log(err);
72-
// Do something for an error here
7372
});
7473
}else{
7574
showAnswerSaveError();
76-
}
77-
}
75+
}}
76+
77+
7878

7979

8080
function showAnswerForm(){

0 commit comments

Comments
 (0)