I define three arrays in my index.js file, but my index.ejs file can only identify the first one?











up vote
1
down vote

favorite












I'm trying to make a to-do list with the 1-3-5 rule, so I create three html forms and want to store them in three different arrays. But my it seems like the .ejs file can only access the task array, but cannot identify task3 and task5.



When I run the code, the browser return: task3 is not defined.
I can't figure out why, please help! Thanks!



index.js (controller)



var express = require("express");
var bodyParser = require("body-parser");

var app = express();

app.use(bodyParser.urlencoded({ extended: true }));
app.set("view engine", "ejs");
//render css files
app.use(express.static("public"));

//placeholders for added task
var task = ;
var task3 = ;
var task5 = ;
//placeholders for removed task
var complete = ;

//post route for adding new task
app.post("/addtask", function(req, res) {
var newTask = req.body.newtask;
task.push(newTask);
res.redirect("/");
});

app.post("/addtask3", function(req, res) {
var newTask = req.body.newtask3;
task3.push(newTask);
res.redirect("/");
});

app.post("/addtask5", function(req, res) {
var newTask = req.body.newtask5;
task5.push(newTask);
res.redirect("/");
});

app.post("/completetask", function(req, res) {
var completeTask = req.body.check;
//check for the "typeof" the different completed task, then add into the complete task
if (typeof completeTask === "string") {
complete.push(completeTask);
//check if the completed task already exits in the task when checked, then remove it
task.splice(task.indexOf(completeTask), 1);
} else if (typeof completeTask === "object") {
for (var i = 0; i < completeTask.length; i++) {
complete.push(completeTask[i]);
task.splice(task.indexOf(completeTask[i]), 1);
}
}
res.redirect("/");
});

app.post("/removetask", function(req, res) {
var removeTask = req.body.check;
//check for the "typeof" the different completed task, then add into the complete task
if (typeof removeTask === "string") {
task.splice(task.indexOf(removeTask), 1);
} else if (typeof removeTask === "object") {
for (var i = 0; i < removeTask.length; i++) {
task.splice(task.indexOf(removeTask[i]), 1);
}
}
res.redirect("/");
});

//render the ejs and display added task, completed task
app.get("/", function(req, res) {
res.render("index", { task: task, complete: complete });
});

//set app to listen on port 3000
app.listen(3000, function() {
console.log("server is running on port 3000");
});


index.ejs (viewer)



<html>
<head>
<title> ToDo App </title>
<link href="https://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet">
<link href="/styles.css" rel="stylesheet">
</head>

<body>
<div class="container">
<h1> ToDo List </h1>
<h2> 1 Big Thing </h2>
<form method="POST">
<p />
<input type="text" name="newtask" placeholder="add big task">
<button formaction="/addtask"> Add </button>
<button formaction="/completetask" type="submit" id="top"> Complete </button>
<button formaction="/removetask" type="submit" id="top"> Delete </button>
<% for( var i = 0; i < task.length; i++){ %>
<li><input type="checkbox" name="check" value="<%= task[i] %>" /> <%= task[i] %> </li>
<% } %>

<h2> 3 Medium Things </h2>
<p />
<input type="text" name="newtask3" placeholder="add medium task">
<button formaction="/addtask3"> Add </button>
<button formaction="/completetask" type="submit" id="top"> Complete </button>
<button formaction="/removetask" type="submit" id="top"> Delete </button>
<% for( var i = 0; i < task3.length; i++){ %>
<li><input type="checkbox" name="check" value="<%= task3[i] %>" /> <%= task3[i] %> </li>
<% } %>

<h2> 5 Small Things </h2>
<p />
<input type="text" name="newtask5" placeholder="add small task">
<button formaction="/addtask5"> Add </button>
<button formaction="/completetask" type="submit" id="top"> Complete </button>
<button formaction="/removetask" type="submit" id="top"> Delete </button>
</form>
<% for( var i = 0; i < task5.length; i++){ %>
<li><input type="checkbox" name="check" value="<%= task5[i] %>" /> <%= task5[i] %> </li>
<% } %>

<h2> Completed task </h2>

<% for(var i = 0; i < complete.length; i++){ %>
<li><input type="checkbox" checked><%= complete[i] %> </li>
<% } %>

</div>

</body>
</html>









share|improve this question
























  • Could you show the code of the controller passing tasks to the view?
    – iagowp
    Nov 21 at 13:32










  • @lagowp I already edit to show the code, please take a look!
    – Alex
    Nov 21 at 14:11















up vote
1
down vote

favorite












I'm trying to make a to-do list with the 1-3-5 rule, so I create three html forms and want to store them in three different arrays. But my it seems like the .ejs file can only access the task array, but cannot identify task3 and task5.



When I run the code, the browser return: task3 is not defined.
I can't figure out why, please help! Thanks!



index.js (controller)



var express = require("express");
var bodyParser = require("body-parser");

var app = express();

app.use(bodyParser.urlencoded({ extended: true }));
app.set("view engine", "ejs");
//render css files
app.use(express.static("public"));

//placeholders for added task
var task = ;
var task3 = ;
var task5 = ;
//placeholders for removed task
var complete = ;

//post route for adding new task
app.post("/addtask", function(req, res) {
var newTask = req.body.newtask;
task.push(newTask);
res.redirect("/");
});

app.post("/addtask3", function(req, res) {
var newTask = req.body.newtask3;
task3.push(newTask);
res.redirect("/");
});

app.post("/addtask5", function(req, res) {
var newTask = req.body.newtask5;
task5.push(newTask);
res.redirect("/");
});

app.post("/completetask", function(req, res) {
var completeTask = req.body.check;
//check for the "typeof" the different completed task, then add into the complete task
if (typeof completeTask === "string") {
complete.push(completeTask);
//check if the completed task already exits in the task when checked, then remove it
task.splice(task.indexOf(completeTask), 1);
} else if (typeof completeTask === "object") {
for (var i = 0; i < completeTask.length; i++) {
complete.push(completeTask[i]);
task.splice(task.indexOf(completeTask[i]), 1);
}
}
res.redirect("/");
});

app.post("/removetask", function(req, res) {
var removeTask = req.body.check;
//check for the "typeof" the different completed task, then add into the complete task
if (typeof removeTask === "string") {
task.splice(task.indexOf(removeTask), 1);
} else if (typeof removeTask === "object") {
for (var i = 0; i < removeTask.length; i++) {
task.splice(task.indexOf(removeTask[i]), 1);
}
}
res.redirect("/");
});

//render the ejs and display added task, completed task
app.get("/", function(req, res) {
res.render("index", { task: task, complete: complete });
});

//set app to listen on port 3000
app.listen(3000, function() {
console.log("server is running on port 3000");
});


index.ejs (viewer)



<html>
<head>
<title> ToDo App </title>
<link href="https://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet">
<link href="/styles.css" rel="stylesheet">
</head>

<body>
<div class="container">
<h1> ToDo List </h1>
<h2> 1 Big Thing </h2>
<form method="POST">
<p />
<input type="text" name="newtask" placeholder="add big task">
<button formaction="/addtask"> Add </button>
<button formaction="/completetask" type="submit" id="top"> Complete </button>
<button formaction="/removetask" type="submit" id="top"> Delete </button>
<% for( var i = 0; i < task.length; i++){ %>
<li><input type="checkbox" name="check" value="<%= task[i] %>" /> <%= task[i] %> </li>
<% } %>

<h2> 3 Medium Things </h2>
<p />
<input type="text" name="newtask3" placeholder="add medium task">
<button formaction="/addtask3"> Add </button>
<button formaction="/completetask" type="submit" id="top"> Complete </button>
<button formaction="/removetask" type="submit" id="top"> Delete </button>
<% for( var i = 0; i < task3.length; i++){ %>
<li><input type="checkbox" name="check" value="<%= task3[i] %>" /> <%= task3[i] %> </li>
<% } %>

<h2> 5 Small Things </h2>
<p />
<input type="text" name="newtask5" placeholder="add small task">
<button formaction="/addtask5"> Add </button>
<button formaction="/completetask" type="submit" id="top"> Complete </button>
<button formaction="/removetask" type="submit" id="top"> Delete </button>
</form>
<% for( var i = 0; i < task5.length; i++){ %>
<li><input type="checkbox" name="check" value="<%= task5[i] %>" /> <%= task5[i] %> </li>
<% } %>

<h2> Completed task </h2>

<% for(var i = 0; i < complete.length; i++){ %>
<li><input type="checkbox" checked><%= complete[i] %> </li>
<% } %>

</div>

</body>
</html>









share|improve this question
























  • Could you show the code of the controller passing tasks to the view?
    – iagowp
    Nov 21 at 13:32










  • @lagowp I already edit to show the code, please take a look!
    – Alex
    Nov 21 at 14:11













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm trying to make a to-do list with the 1-3-5 rule, so I create three html forms and want to store them in three different arrays. But my it seems like the .ejs file can only access the task array, but cannot identify task3 and task5.



When I run the code, the browser return: task3 is not defined.
I can't figure out why, please help! Thanks!



index.js (controller)



var express = require("express");
var bodyParser = require("body-parser");

var app = express();

app.use(bodyParser.urlencoded({ extended: true }));
app.set("view engine", "ejs");
//render css files
app.use(express.static("public"));

//placeholders for added task
var task = ;
var task3 = ;
var task5 = ;
//placeholders for removed task
var complete = ;

//post route for adding new task
app.post("/addtask", function(req, res) {
var newTask = req.body.newtask;
task.push(newTask);
res.redirect("/");
});

app.post("/addtask3", function(req, res) {
var newTask = req.body.newtask3;
task3.push(newTask);
res.redirect("/");
});

app.post("/addtask5", function(req, res) {
var newTask = req.body.newtask5;
task5.push(newTask);
res.redirect("/");
});

app.post("/completetask", function(req, res) {
var completeTask = req.body.check;
//check for the "typeof" the different completed task, then add into the complete task
if (typeof completeTask === "string") {
complete.push(completeTask);
//check if the completed task already exits in the task when checked, then remove it
task.splice(task.indexOf(completeTask), 1);
} else if (typeof completeTask === "object") {
for (var i = 0; i < completeTask.length; i++) {
complete.push(completeTask[i]);
task.splice(task.indexOf(completeTask[i]), 1);
}
}
res.redirect("/");
});

app.post("/removetask", function(req, res) {
var removeTask = req.body.check;
//check for the "typeof" the different completed task, then add into the complete task
if (typeof removeTask === "string") {
task.splice(task.indexOf(removeTask), 1);
} else if (typeof removeTask === "object") {
for (var i = 0; i < removeTask.length; i++) {
task.splice(task.indexOf(removeTask[i]), 1);
}
}
res.redirect("/");
});

//render the ejs and display added task, completed task
app.get("/", function(req, res) {
res.render("index", { task: task, complete: complete });
});

//set app to listen on port 3000
app.listen(3000, function() {
console.log("server is running on port 3000");
});


index.ejs (viewer)



<html>
<head>
<title> ToDo App </title>
<link href="https://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet">
<link href="/styles.css" rel="stylesheet">
</head>

<body>
<div class="container">
<h1> ToDo List </h1>
<h2> 1 Big Thing </h2>
<form method="POST">
<p />
<input type="text" name="newtask" placeholder="add big task">
<button formaction="/addtask"> Add </button>
<button formaction="/completetask" type="submit" id="top"> Complete </button>
<button formaction="/removetask" type="submit" id="top"> Delete </button>
<% for( var i = 0; i < task.length; i++){ %>
<li><input type="checkbox" name="check" value="<%= task[i] %>" /> <%= task[i] %> </li>
<% } %>

<h2> 3 Medium Things </h2>
<p />
<input type="text" name="newtask3" placeholder="add medium task">
<button formaction="/addtask3"> Add </button>
<button formaction="/completetask" type="submit" id="top"> Complete </button>
<button formaction="/removetask" type="submit" id="top"> Delete </button>
<% for( var i = 0; i < task3.length; i++){ %>
<li><input type="checkbox" name="check" value="<%= task3[i] %>" /> <%= task3[i] %> </li>
<% } %>

<h2> 5 Small Things </h2>
<p />
<input type="text" name="newtask5" placeholder="add small task">
<button formaction="/addtask5"> Add </button>
<button formaction="/completetask" type="submit" id="top"> Complete </button>
<button formaction="/removetask" type="submit" id="top"> Delete </button>
</form>
<% for( var i = 0; i < task5.length; i++){ %>
<li><input type="checkbox" name="check" value="<%= task5[i] %>" /> <%= task5[i] %> </li>
<% } %>

<h2> Completed task </h2>

<% for(var i = 0; i < complete.length; i++){ %>
<li><input type="checkbox" checked><%= complete[i] %> </li>
<% } %>

</div>

</body>
</html>









share|improve this question















I'm trying to make a to-do list with the 1-3-5 rule, so I create three html forms and want to store them in three different arrays. But my it seems like the .ejs file can only access the task array, but cannot identify task3 and task5.



When I run the code, the browser return: task3 is not defined.
I can't figure out why, please help! Thanks!



index.js (controller)



var express = require("express");
var bodyParser = require("body-parser");

var app = express();

app.use(bodyParser.urlencoded({ extended: true }));
app.set("view engine", "ejs");
//render css files
app.use(express.static("public"));

//placeholders for added task
var task = ;
var task3 = ;
var task5 = ;
//placeholders for removed task
var complete = ;

//post route for adding new task
app.post("/addtask", function(req, res) {
var newTask = req.body.newtask;
task.push(newTask);
res.redirect("/");
});

app.post("/addtask3", function(req, res) {
var newTask = req.body.newtask3;
task3.push(newTask);
res.redirect("/");
});

app.post("/addtask5", function(req, res) {
var newTask = req.body.newtask5;
task5.push(newTask);
res.redirect("/");
});

app.post("/completetask", function(req, res) {
var completeTask = req.body.check;
//check for the "typeof" the different completed task, then add into the complete task
if (typeof completeTask === "string") {
complete.push(completeTask);
//check if the completed task already exits in the task when checked, then remove it
task.splice(task.indexOf(completeTask), 1);
} else if (typeof completeTask === "object") {
for (var i = 0; i < completeTask.length; i++) {
complete.push(completeTask[i]);
task.splice(task.indexOf(completeTask[i]), 1);
}
}
res.redirect("/");
});

app.post("/removetask", function(req, res) {
var removeTask = req.body.check;
//check for the "typeof" the different completed task, then add into the complete task
if (typeof removeTask === "string") {
task.splice(task.indexOf(removeTask), 1);
} else if (typeof removeTask === "object") {
for (var i = 0; i < removeTask.length; i++) {
task.splice(task.indexOf(removeTask[i]), 1);
}
}
res.redirect("/");
});

//render the ejs and display added task, completed task
app.get("/", function(req, res) {
res.render("index", { task: task, complete: complete });
});

//set app to listen on port 3000
app.listen(3000, function() {
console.log("server is running on port 3000");
});


index.ejs (viewer)



<html>
<head>
<title> ToDo App </title>
<link href="https://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet">
<link href="/styles.css" rel="stylesheet">
</head>

<body>
<div class="container">
<h1> ToDo List </h1>
<h2> 1 Big Thing </h2>
<form method="POST">
<p />
<input type="text" name="newtask" placeholder="add big task">
<button formaction="/addtask"> Add </button>
<button formaction="/completetask" type="submit" id="top"> Complete </button>
<button formaction="/removetask" type="submit" id="top"> Delete </button>
<% for( var i = 0; i < task.length; i++){ %>
<li><input type="checkbox" name="check" value="<%= task[i] %>" /> <%= task[i] %> </li>
<% } %>

<h2> 3 Medium Things </h2>
<p />
<input type="text" name="newtask3" placeholder="add medium task">
<button formaction="/addtask3"> Add </button>
<button formaction="/completetask" type="submit" id="top"> Complete </button>
<button formaction="/removetask" type="submit" id="top"> Delete </button>
<% for( var i = 0; i < task3.length; i++){ %>
<li><input type="checkbox" name="check" value="<%= task3[i] %>" /> <%= task3[i] %> </li>
<% } %>

<h2> 5 Small Things </h2>
<p />
<input type="text" name="newtask5" placeholder="add small task">
<button formaction="/addtask5"> Add </button>
<button formaction="/completetask" type="submit" id="top"> Complete </button>
<button formaction="/removetask" type="submit" id="top"> Delete </button>
</form>
<% for( var i = 0; i < task5.length; i++){ %>
<li><input type="checkbox" name="check" value="<%= task5[i] %>" /> <%= task5[i] %> </li>
<% } %>

<h2> Completed task </h2>

<% for(var i = 0; i < complete.length; i++){ %>
<li><input type="checkbox" checked><%= complete[i] %> </li>
<% } %>

</div>

</body>
</html>






javascript node.js express ejs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 14:10

























asked Nov 21 at 13:28









Alex

145




145












  • Could you show the code of the controller passing tasks to the view?
    – iagowp
    Nov 21 at 13:32










  • @lagowp I already edit to show the code, please take a look!
    – Alex
    Nov 21 at 14:11


















  • Could you show the code of the controller passing tasks to the view?
    – iagowp
    Nov 21 at 13:32










  • @lagowp I already edit to show the code, please take a look!
    – Alex
    Nov 21 at 14:11
















Could you show the code of the controller passing tasks to the view?
– iagowp
Nov 21 at 13:32




Could you show the code of the controller passing tasks to the view?
– iagowp
Nov 21 at 13:32












@lagowp I already edit to show the code, please take a look!
– Alex
Nov 21 at 14:11




@lagowp I already edit to show the code, please take a look!
– Alex
Nov 21 at 14:11












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










Your problem is with what you are sending to your view



app.get("/", function(req, res) {
res.render("index", { task: task, complete: complete });
});


You see? you are rendering the view index, passing two objects to it, task and complete. Then, on your view, you try to access task3, but you've never sent it. For your code to run, you should change this line to



app.get("/", function(req, res) {
res.render("index", { task: task, task3: task3, task5: task5, complete: complete });
});


Or this, if you are using a modern version of node



app.get("/", function(req, res) {
res.render("index", { task, task3, task5, complete });
});





share|improve this answer





















  • Yea I just figured it out just now >.<, but thank you anyway!
    – Alex
    Nov 21 at 14:59


















up vote
0
down vote













Because when you are rendering the page you are only sending task from server you are not sending task3 and task5 you need to send them too.



before it was



//render the ejs and display added task, completed task
app.get("/", function(req, res) {
res.render("index", { task: task, complete: complete });
});


it should be something like below



//render the ejs and display added task, completed task
app.get("/", function(req, res) {
res.render("index", { task: task,task3:task3, task5:task5, complete: complete });


});






share|improve this answer





















  • Yea I just figured it out just now >.<, but thank you anyway!
    – Alex
    Nov 21 at 15:00











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413118%2fi-define-three-arrays-in-my-index-js-file-but-my-index-ejs-file-can-only-identi%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Your problem is with what you are sending to your view



app.get("/", function(req, res) {
res.render("index", { task: task, complete: complete });
});


You see? you are rendering the view index, passing two objects to it, task and complete. Then, on your view, you try to access task3, but you've never sent it. For your code to run, you should change this line to



app.get("/", function(req, res) {
res.render("index", { task: task, task3: task3, task5: task5, complete: complete });
});


Or this, if you are using a modern version of node



app.get("/", function(req, res) {
res.render("index", { task, task3, task5, complete });
});





share|improve this answer





















  • Yea I just figured it out just now >.<, but thank you anyway!
    – Alex
    Nov 21 at 14:59















up vote
1
down vote



accepted










Your problem is with what you are sending to your view



app.get("/", function(req, res) {
res.render("index", { task: task, complete: complete });
});


You see? you are rendering the view index, passing two objects to it, task and complete. Then, on your view, you try to access task3, but you've never sent it. For your code to run, you should change this line to



app.get("/", function(req, res) {
res.render("index", { task: task, task3: task3, task5: task5, complete: complete });
});


Or this, if you are using a modern version of node



app.get("/", function(req, res) {
res.render("index", { task, task3, task5, complete });
});





share|improve this answer





















  • Yea I just figured it out just now >.<, but thank you anyway!
    – Alex
    Nov 21 at 14:59













up vote
1
down vote



accepted







up vote
1
down vote



accepted






Your problem is with what you are sending to your view



app.get("/", function(req, res) {
res.render("index", { task: task, complete: complete });
});


You see? you are rendering the view index, passing two objects to it, task and complete. Then, on your view, you try to access task3, but you've never sent it. For your code to run, you should change this line to



app.get("/", function(req, res) {
res.render("index", { task: task, task3: task3, task5: task5, complete: complete });
});


Or this, if you are using a modern version of node



app.get("/", function(req, res) {
res.render("index", { task, task3, task5, complete });
});





share|improve this answer












Your problem is with what you are sending to your view



app.get("/", function(req, res) {
res.render("index", { task: task, complete: complete });
});


You see? you are rendering the view index, passing two objects to it, task and complete. Then, on your view, you try to access task3, but you've never sent it. For your code to run, you should change this line to



app.get("/", function(req, res) {
res.render("index", { task: task, task3: task3, task5: task5, complete: complete });
});


Or this, if you are using a modern version of node



app.get("/", function(req, res) {
res.render("index", { task, task3, task5, complete });
});






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 at 14:32









iagowp

809523




809523












  • Yea I just figured it out just now >.<, but thank you anyway!
    – Alex
    Nov 21 at 14:59


















  • Yea I just figured it out just now >.<, but thank you anyway!
    – Alex
    Nov 21 at 14:59
















Yea I just figured it out just now >.<, but thank you anyway!
– Alex
Nov 21 at 14:59




Yea I just figured it out just now >.<, but thank you anyway!
– Alex
Nov 21 at 14:59












up vote
0
down vote













Because when you are rendering the page you are only sending task from server you are not sending task3 and task5 you need to send them too.



before it was



//render the ejs and display added task, completed task
app.get("/", function(req, res) {
res.render("index", { task: task, complete: complete });
});


it should be something like below



//render the ejs and display added task, completed task
app.get("/", function(req, res) {
res.render("index", { task: task,task3:task3, task5:task5, complete: complete });


});






share|improve this answer





















  • Yea I just figured it out just now >.<, but thank you anyway!
    – Alex
    Nov 21 at 15:00















up vote
0
down vote













Because when you are rendering the page you are only sending task from server you are not sending task3 and task5 you need to send them too.



before it was



//render the ejs and display added task, completed task
app.get("/", function(req, res) {
res.render("index", { task: task, complete: complete });
});


it should be something like below



//render the ejs and display added task, completed task
app.get("/", function(req, res) {
res.render("index", { task: task,task3:task3, task5:task5, complete: complete });


});






share|improve this answer





















  • Yea I just figured it out just now >.<, but thank you anyway!
    – Alex
    Nov 21 at 15:00













up vote
0
down vote










up vote
0
down vote









Because when you are rendering the page you are only sending task from server you are not sending task3 and task5 you need to send them too.



before it was



//render the ejs and display added task, completed task
app.get("/", function(req, res) {
res.render("index", { task: task, complete: complete });
});


it should be something like below



//render the ejs and display added task, completed task
app.get("/", function(req, res) {
res.render("index", { task: task,task3:task3, task5:task5, complete: complete });


});






share|improve this answer












Because when you are rendering the page you are only sending task from server you are not sending task3 and task5 you need to send them too.



before it was



//render the ejs and display added task, completed task
app.get("/", function(req, res) {
res.render("index", { task: task, complete: complete });
});


it should be something like below



//render the ejs and display added task, completed task
app.get("/", function(req, res) {
res.render("index", { task: task,task3:task3, task5:task5, complete: complete });


});







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 at 14:37









ahmed waqas nasir

215




215












  • Yea I just figured it out just now >.<, but thank you anyway!
    – Alex
    Nov 21 at 15:00


















  • Yea I just figured it out just now >.<, but thank you anyway!
    – Alex
    Nov 21 at 15:00
















Yea I just figured it out just now >.<, but thank you anyway!
– Alex
Nov 21 at 15:00




Yea I just figured it out just now >.<, but thank you anyway!
– Alex
Nov 21 at 15:00


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413118%2fi-define-three-arrays-in-my-index-js-file-but-my-index-ejs-file-can-only-identi%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)