From b58cc652dd5647e491beb70eb9c864b0ad660494 Mon Sep 17 00:00:00 2001 From: DarianRushworth Date: Tue, 25 Aug 2020 10:02:37 +0200 Subject: [PATCH 1/7] Added total exp to users --- migrations/0-create-user.js | 4 ++++ models/user.js | 4 ++++ seeders/0-users.js | 2 ++ 3 files changed, 10 insertions(+) diff --git a/migrations/0-create-user.js b/migrations/0-create-user.js index 94212a8..a85e7bb 100644 --- a/migrations/0-create-user.js +++ b/migrations/0-create-user.js @@ -29,6 +29,10 @@ module.exports = { type: Sequelize.STRING, allowNull: false, }, + totalExp: { + type: Sequelize.INTEGER, + allowNull: false, + }, createdAt: { allowNull: false, type: Sequelize.DATE, diff --git a/models/user.js b/models/user.js index 5881b12..3fa3788 100644 --- a/models/user.js +++ b/models/user.js @@ -37,6 +37,10 @@ module.exports = (sequelize, DataTypes) => { ranking: { type: DataTypes.STRING, allowNull: false, + }, + totalExp: { + type: DataTypes.INTEGER, + allowNull: false, } }, { diff --git a/seeders/0-users.js b/seeders/0-users.js index fa4ee35..d375ec2 100644 --- a/seeders/0-users.js +++ b/seeders/0-users.js @@ -13,6 +13,7 @@ module.exports = { email: "test@test.com", password: bcrypt.hashSync("test1234", SALT_ROUNDS), ranking: "Code Monkey", + totalExp: 60, createdAt: new Date(), updatedAt: new Date(), }, @@ -22,6 +23,7 @@ module.exports = { email: "a@a.com", password: bcrypt.hashSync("a", SALT_ROUNDS), ranking: "Code Monkey", + totalExp: 50, createdAt: new Date(), updatedAt: new Date(), }, From 0559432b67a06342aaf93076812fd8e0e2a7a387 Mon Sep 17 00:00:00 2001 From: DarianRushworth Date: Tue, 25 Aug 2020 10:21:16 +0200 Subject: [PATCH 2/7] Setup two new models --- .../20200825081015-create-quiz-question.js | 42 +++++++++++++++++++ .../20200825081201-create-completed-quiz.js | 33 +++++++++++++++ models/completedquiz.js | 25 +++++++++++ models/quizquestion.js | 28 +++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 migrations/20200825081015-create-quiz-question.js create mode 100644 migrations/20200825081201-create-completed-quiz.js create mode 100644 models/completedquiz.js create mode 100644 models/quizquestion.js diff --git a/migrations/20200825081015-create-quiz-question.js b/migrations/20200825081015-create-quiz-question.js new file mode 100644 index 0000000..dcb3892 --- /dev/null +++ b/migrations/20200825081015-create-quiz-question.js @@ -0,0 +1,42 @@ +'use strict'; +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.createTable('quizQuestions', { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: Sequelize.INTEGER + }, + question: { + type: Sequelize.TEXT + }, + answer: { + type: Sequelize.TEXT + }, + incorrect1: { + type: Sequelize.TEXT + }, + incorrect2: { + type: Sequelize.TEXT + }, + incorrect3: { + type: Sequelize.TEXT + }, + exerciseId: { + type: Sequelize.INTEGER + }, + createdAt: { + allowNull: false, + type: Sequelize.DATE + }, + updatedAt: { + allowNull: false, + type: Sequelize.DATE + } + }); + }, + down: async (queryInterface, Sequelize) => { + await queryInterface.dropTable('quizQuestions'); + } +}; \ No newline at end of file diff --git a/migrations/20200825081201-create-completed-quiz.js b/migrations/20200825081201-create-completed-quiz.js new file mode 100644 index 0000000..67d26c1 --- /dev/null +++ b/migrations/20200825081201-create-completed-quiz.js @@ -0,0 +1,33 @@ +'use strict'; +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.createTable('completedQuizzes', { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: Sequelize.INTEGER + }, + userId: { + type: Sequelize.INTEGER + }, + quizQuestionId: { + type: Sequelize.INTEGER + }, + exp: { + type: Sequelize.INTEGER + }, + createdAt: { + allowNull: false, + type: Sequelize.DATE + }, + updatedAt: { + allowNull: false, + type: Sequelize.DATE + } + }); + }, + down: async (queryInterface, Sequelize) => { + await queryInterface.dropTable('completedQuizzes'); + } +}; \ No newline at end of file diff --git a/models/completedquiz.js b/models/completedquiz.js new file mode 100644 index 0000000..87d10a0 --- /dev/null +++ b/models/completedquiz.js @@ -0,0 +1,25 @@ +'use strict'; +const { + Model +} = require('sequelize'); +module.exports = (sequelize, DataTypes) => { + class completedQuiz extends Model { + /** + * Helper method for defining associations. + * This method is not a part of Sequelize lifecycle. + * The `models/index` file will call this method automatically. + */ + static associate(models) { + // define association here + } + }; + completedQuiz.init({ + userId: DataTypes.INTEGER, + quizQuestionId: DataTypes.INTEGER, + exp: DataTypes.INTEGER + }, { + sequelize, + modelName: 'completedQuiz', + }); + return completedQuiz; +}; \ No newline at end of file diff --git a/models/quizquestion.js b/models/quizquestion.js new file mode 100644 index 0000000..ae2017c --- /dev/null +++ b/models/quizquestion.js @@ -0,0 +1,28 @@ +'use strict'; +const { + Model +} = require('sequelize'); +module.exports = (sequelize, DataTypes) => { + class quizQuestion extends Model { + /** + * Helper method for defining associations. + * This method is not a part of Sequelize lifecycle. + * The `models/index` file will call this method automatically. + */ + static associate(models) { + // define association here + } + }; + quizQuestion.init({ + question: DataTypes.TEXT, + answer: DataTypes.TEXT, + incorrect1: DataTypes.TEXT, + incorrect2: DataTypes.TEXT, + incorrect3: DataTypes.TEXT, + exerciseId: DataTypes.INTEGER + }, { + sequelize, + modelName: 'quizQuestion', + }); + return quizQuestion; +}; \ No newline at end of file From 0e0ce28f2feeed10134149482a104c3780e0eaa2 Mon Sep 17 00:00:00 2001 From: DarianRushworth Date: Tue, 25 Aug 2020 10:35:33 +0200 Subject: [PATCH 3/7] Restrictions set in place and relations setup --- ...-question.js => 3-create-quiz-question.js} | 24 ++++++++--- ...ted-quiz.js => 4-create-completed-quiz.js} | 21 ++++++++-- models/completedquiz.js | 27 ++++++++++-- models/exercise.js | 1 + models/quizquestion.js | 41 +++++++++++++++---- models/user.js | 4 ++ 6 files changed, 99 insertions(+), 19 deletions(-) rename migrations/{20200825081015-create-quiz-question.js => 3-create-quiz-question.js} (59%) rename migrations/{20200825081201-create-completed-quiz.js => 4-create-completed-quiz.js} (58%) diff --git a/migrations/20200825081015-create-quiz-question.js b/migrations/3-create-quiz-question.js similarity index 59% rename from migrations/20200825081015-create-quiz-question.js rename to migrations/3-create-quiz-question.js index dcb3892..42b03b5 100644 --- a/migrations/20200825081015-create-quiz-question.js +++ b/migrations/3-create-quiz-question.js @@ -9,22 +9,34 @@ module.exports = { type: Sequelize.INTEGER }, question: { - type: Sequelize.TEXT + type: Sequelize.TEXT, + allowNull: false, }, answer: { - type: Sequelize.TEXT + type: Sequelize.TEXT, + allowNull: false, }, incorrect1: { - type: Sequelize.TEXT + type: Sequelize.TEXT, + allowNull: false, }, incorrect2: { - type: Sequelize.TEXT + type: Sequelize.TEXT, + allowNull: false, }, incorrect3: { - type: Sequelize.TEXT + type: Sequelize.TEXT, + allowNull: false, }, exerciseId: { - type: Sequelize.INTEGER + type: Sequelize.INTEGER, + allowNull: false, + references: { + model: "exercises", + key: "id", + }, + onUpdate: "CASACDE", + onDelete: "SET NULL", }, createdAt: { allowNull: false, diff --git a/migrations/20200825081201-create-completed-quiz.js b/migrations/4-create-completed-quiz.js similarity index 58% rename from migrations/20200825081201-create-completed-quiz.js rename to migrations/4-create-completed-quiz.js index 67d26c1..fcbe565 100644 --- a/migrations/20200825081201-create-completed-quiz.js +++ b/migrations/4-create-completed-quiz.js @@ -9,13 +9,28 @@ module.exports = { type: Sequelize.INTEGER }, userId: { - type: Sequelize.INTEGER + type: Sequelize.INTEGER, + allowNull: false, + references: { + model: "users", + key: "id", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", }, quizQuestionId: { - type: Sequelize.INTEGER + type: Sequelize.INTEGER, + allowNull: false, + references: { + model: "quizQuestions", + key: "id", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", }, exp: { - type: Sequelize.INTEGER + type: Sequelize.INTEGER, + allowNull: false, }, createdAt: { allowNull: false, diff --git a/models/completedquiz.js b/models/completedquiz.js index 87d10a0..c695ac8 100644 --- a/models/completedquiz.js +++ b/models/completedquiz.js @@ -14,9 +14,30 @@ module.exports = (sequelize, DataTypes) => { } }; completedQuiz.init({ - userId: DataTypes.INTEGER, - quizQuestionId: DataTypes.INTEGER, - exp: DataTypes.INTEGER + userId: { + type: DataTypes.INTEGER, + allowNull: false, + references: { + model: "users", + key: "id", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }, + quizQuestionId: { + type: DataTypes.INTEGER, + allowNull: false, + references: { + model: "quizQuestions", + key: "id", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }, + exp: { + type: DataTypes.INTEGER, + allowNull: false, + } }, { sequelize, modelName: 'completedQuiz', diff --git a/models/exercise.js b/models/exercise.js index 598f100..f343e97 100644 --- a/models/exercise.js +++ b/models/exercise.js @@ -10,6 +10,7 @@ module.exports = (sequelize, DataTypes) => { * The `models/index` file will call this method automatically. */ static associate(models) { + exercise.hasMany(models.quizQuestion) exercise.belongsToMany(models.user, { through: "completedExercises", key: "exerciseId", diff --git a/models/quizquestion.js b/models/quizquestion.js index ae2017c..72c6c90 100644 --- a/models/quizquestion.js +++ b/models/quizquestion.js @@ -10,16 +10,43 @@ module.exports = (sequelize, DataTypes) => { * The `models/index` file will call this method automatically. */ static associate(models) { - // define association here + quizQuestion.belongsToMany(models.user, { + through: "completedQuiz", + key: "quizQuestionId", + }) } }; quizQuestion.init({ - question: DataTypes.TEXT, - answer: DataTypes.TEXT, - incorrect1: DataTypes.TEXT, - incorrect2: DataTypes.TEXT, - incorrect3: DataTypes.TEXT, - exerciseId: DataTypes.INTEGER + question: { + type: DataTypes.TEXT, + allowNull: false, + }, + answer: { + type: DataTypes.TEXT, + allowNull: false, + }, + incorrect1: { + type: DataTypes.TEXT, + allowNull: false, + }, + incorrect2: { + type: DataTypes.TEXT, + allowNull: false, + }, + incorrect3: { + type: DataTypes.TEXT, + allowNull: false, + }, + exerciseId: { + type: DataTypes.INTEGER, + allowNull: false, + references: { + model: "exercises", + key: "id", + }, + onUpdate: "CASCADE", + onDelete: "SET NULL", + } }, { sequelize, modelName: 'quizQuestion', diff --git a/models/user.js b/models/user.js index 3fa3788..c2de02a 100644 --- a/models/user.js +++ b/models/user.js @@ -13,6 +13,10 @@ module.exports = (sequelize, DataTypes) => { through: "completedExercises", key: "userId", }) + user.belongsToMany(models.quizQuestion, { + through: "completedQuiz", + key: "userId", + }) } } user.init( From 2d627c715ba5134f092efceb4f115e5cee1a8467 Mon Sep 17 00:00:00 2001 From: DarianRushworth Date: Tue, 25 Aug 2020 10:52:20 +0200 Subject: [PATCH 4/7] Seeders setup, awaiting information, relations editted and running smoothly --- migrations/3-create-quiz-question.js | 2 +- models/quizquestion.js | 2 +- models/user.js | 2 +- seeders/3-some-quizQuestions.js | 23 +++++++++++++++++++++++ seeders/4-some-completedQuiz.js | 20 ++++++++++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 seeders/3-some-quizQuestions.js create mode 100644 seeders/4-some-completedQuiz.js diff --git a/migrations/3-create-quiz-question.js b/migrations/3-create-quiz-question.js index 42b03b5..8d06f75 100644 --- a/migrations/3-create-quiz-question.js +++ b/migrations/3-create-quiz-question.js @@ -35,7 +35,7 @@ module.exports = { model: "exercises", key: "id", }, - onUpdate: "CASACDE", + onUpdate: "CASCADE", onDelete: "SET NULL", }, createdAt: { diff --git a/models/quizquestion.js b/models/quizquestion.js index 72c6c90..dcd313b 100644 --- a/models/quizquestion.js +++ b/models/quizquestion.js @@ -11,7 +11,7 @@ module.exports = (sequelize, DataTypes) => { */ static associate(models) { quizQuestion.belongsToMany(models.user, { - through: "completedQuiz", + through: "completedQuizzes", key: "quizQuestionId", }) } diff --git a/models/user.js b/models/user.js index c2de02a..2c0afac 100644 --- a/models/user.js +++ b/models/user.js @@ -14,7 +14,7 @@ module.exports = (sequelize, DataTypes) => { key: "userId", }) user.belongsToMany(models.quizQuestion, { - through: "completedQuiz", + through: "completedQuizzes", key: "userId", }) } diff --git a/seeders/3-some-quizQuestions.js b/seeders/3-some-quizQuestions.js new file mode 100644 index 0000000..c265ab3 --- /dev/null +++ b/seeders/3-some-quizQuestions.js @@ -0,0 +1,23 @@ +'use strict'; + +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.bulkInsert( + 'quizQuestions', [ + { + question: "What is my name?", + answer: "darian", + incorrect1: "Susuan", + incorrect2: "Brad", + incorrect3: "Brent", + exerciseId: 1, + createdAt: new Date(), + updatedAt: new Date(), + } + ] + )}, + + down: async (queryInterface, Sequelize) => { + await queryInterface.bulkDelete('quizQuestions', null, {}); + } +}; diff --git a/seeders/4-some-completedQuiz.js b/seeders/4-some-completedQuiz.js new file mode 100644 index 0000000..1f73441 --- /dev/null +++ b/seeders/4-some-completedQuiz.js @@ -0,0 +1,20 @@ +'use strict'; + +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.bulkInsert( + 'completedQuizzes', [ + { + userId: 1, + quizQuestionId: 1, + exp: 10, + createdAt: new Date(), + updatedAt: new Date(), + } + ] + )}, + + down: async (queryInterface, Sequelize) => { + await queryInterface.bulkDelete('completedQuizzes', null, {}); + } +}; From 891a630919d05714011aab7ad52f07ec8b5e943b Mon Sep 17 00:00:00 2001 From: DarianRushworth Date: Tue, 25 Aug 2020 11:41:19 +0200 Subject: [PATCH 5/7] Router added for quiz questions, edit on other PATCH router --- routers/exercisesRouter.js | 104 ++++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) diff --git a/routers/exercisesRouter.js b/routers/exercisesRouter.js index 1f5079b..46e248e 100644 --- a/routers/exercisesRouter.js +++ b/routers/exercisesRouter.js @@ -1,8 +1,11 @@ const { Router } = require("express") const authMiddleware = require("../auth/middleware") +const User = require("../models").user const Exercises = require("../models").exercise const CompletedExercises = require("../models").completedExercise +const QuizQuestions = require("../models").quizQuestion +const CompletedQuizzes = require("../models").completedQuiz const router = new Router() @@ -51,6 +54,57 @@ router.get( } ) +router.patch( + "/:id/quiz/completed", + authMiddleware, + async(req, res, next) => { + const userIdNeeded = req.user.id + // console.log("user ID test", userIdNeeded) + if(!userIdNeeded){ + res.status(401).send("Sorry you aren't authorized, please login/sign-up to authorize yourself.") + } + + const quizIdNeeded = parseInt(req.params.id) + // console.log("quiz ID test", quizIdNeeded) + if(!quizIdNeeded){ + res.status(400).send("The Url malfunctioned please refresh and try again.") + } + + try{ + const quizComplete = await CompletedQuizzes.create({ + userId: userIdNeeded, + quizQuestionId: quizIdNeeded, + exp: 10, + }) + console.log("created quiz test", quizComplete) + if(!quizComplete){ + res.status(404).send("Your info couldnt be processed, refresh and try again.") + } + + const userFound = await User.findByPk(userIdNeeded) + if(!userFound){ + res.status(404).send("Oops, we seem to be lost please login/sign-up so we can find you.") + } + + const updateExpUser = await userFound.increment("totalExp", { by: 10}) + // console.log("exp update test", updateExpUser) + if(!updateExpUser){ + res.status(400).send("Your exp wasnt updated please refresh and try again.") + } else { + delete updateExpUser.dataValues["password"] + res.status(202).send({ + user: {...updateExpUser.dataValues}, + completedQuiz: quizComplete, + }) + } + + + } catch(error){ + next(error) + } + } +) + router.patch( "/:id/completed", authMiddleware, @@ -113,8 +167,56 @@ router.patch( }) if(!sendExercise){ res.status(404).send("We couldn't find you're completed exercises, please refresh and try again.") + } + + const userFound = await User.findByPk(userIdNeeded) + if(!userFound){ + res.status(404).send("Oops, we seem to be lost please login/sign-up so we can find you.") + } + + const updateUser = await userFound.increment("totalExp", { by: expInt}) + if(!updateUser){ + res.status(400).send("Oops, it seems yuor exp hasnt updated please refresh and try again.") + } else { + delete updateUser.dataValues["password"] + res.status(202).send({ + user: {...updateUser.dataValues}, + completed: sendExercise, + }) + } + + } catch(error){ + next(error) + } + } +) + +router.get( + "/:id/quiz", + authMiddleware, + async(req, res, next) => { + + if(!req.user){ + res.status(401).send("Sorry you aren't authorized, please login/sign-up to authorize yourself.") + } + + const exerciseIdNeeded = parseInt(req.params.id) + // console.log("questions ID test", exerciseIdNeeded) + if(!exerciseIdNeeded){ + res.status(400).send("Url malfunctioned, please refresh and try again.") + } + + try{ + const fecthQuizzes = await QuizQuestions.findAll({ + where: { + exerciseId: exerciseIdNeeded, + } + }) + // console.log("fetced quiz questions", fecthQuizzes) + if(!fecthQuizzes){ + res.status(404).send("It seems our quizzes have vanished, give us a moment will we find them. Refresh to help us.") } else { - res.status(202).send(sendExercise) + res.status(202).send(fecthQuizzes) } } catch(error){ From f907ed9a432c05e7936a5c619fb7997c8ffe10e0 Mon Sep 17 00:00:00 2001 From: DarianRushworth Date: Tue, 25 Aug 2020 12:11:08 +0200 Subject: [PATCH 6/7] Adding proper questions to seeders --- seeders/3-some-quizQuestions.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/seeders/3-some-quizQuestions.js b/seeders/3-some-quizQuestions.js index c265ab3..a3ae5d9 100644 --- a/seeders/3-some-quizQuestions.js +++ b/seeders/3-some-quizQuestions.js @@ -5,15 +5,25 @@ module.exports = { await queryInterface.bulkInsert( 'quizQuestions', [ { - question: "What is my name?", - answer: "darian", - incorrect1: "Susuan", - incorrect2: "Brad", - incorrect3: "Brent", + question: "What does the Map() accomplish?", + answer: "Creates a new array populated with the results of calling a provided function on every element in the calling array.", + incorrect1: "Calls a provided callback function once for each element in the array, that transforms the old array.", + incorrect2: "It calls for all elements of the array including the missing elements and creates a new array with the results.", + incorrect3: "Populates the original array with the results of calling a provided function on every element in the calling array.", exerciseId: 1, createdAt: new Date(), updatedAt: new Date(), - } + }, + { + question: "Which of these answers uses the correct syntax for the Map()", + answer: "array.map( x => x * a)", + incorrect1: "array.map(x * a)", + incorrect2: "array.map(() = x => x * a)", + incorrect3: "array.map(x = x * a)", + exerciseId: 1, + createdAt: new Date(), + updatedAt: new Date(), + }, ] )}, From 28708d0d932e550d5d11624e6f10d517d550be09 Mon Sep 17 00:00:00 2001 From: DarianRushworth Date: Tue, 25 Aug 2020 13:23:53 +0200 Subject: [PATCH 7/7] Quiz questions set in models --- seeders/3-some-quizQuestions.js | 271 ++++++++++++++++++++++++++++++++ 1 file changed, 271 insertions(+) diff --git a/seeders/3-some-quizQuestions.js b/seeders/3-some-quizQuestions.js index a3ae5d9..bc68f66 100644 --- a/seeders/3-some-quizQuestions.js +++ b/seeders/3-some-quizQuestions.js @@ -24,6 +24,277 @@ module.exports = { createdAt: new Date(), updatedAt: new Date(), }, + { + question: "What does the Filter() accomplish?", + answer: "filters the data in the array according to a condition", + incorrect1: "filters the data in the array and always returns one", + incorrect2: "filters the data in the array and returns the index of all", + incorrect3: "filters the data and removes elements of the array according to a condition.", + exerciseId: 2, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: `What is the outcome of the following code? + const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present']; + const result = words.filter(word => word.length > 6);`, + answer: "Array ['exuberant', 'destruction', 'present’]", + incorrect1: 'Array ["present"]', + incorrect2: "Array [spray, limit, elite, exuberant, destruction, present]", + incorrect3: "Array [exuberant, destruction, present]", + exerciseId: 2, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: "What does the Find() accomplish?", + answer: "returns the first element in the array that fits the condition", + incorrect1: "returns all the elements in the array that fit the condition", + incorrect2: "finds the correct spot in the array so you can add an element in there.", + incorrect3: "returns the last element in the array that fits the condition", + exerciseId: 3, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: `What is the outcome of the following code? + const numberOfMonkeys = [ 3, 12, 8, 35, 15 ] + const result = numberOfMonkeys.find(monkeys => monkeys > 10)`, + answer: "12", + incorrect1: "12, 35, 15", + incorrect2: "12, 8, 35, 15", + incorrect3: "none of the above ", + exerciseId: 3, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: "What does the Pop() accomplish?", + answer: "Removes the last item from an array and returns it. ", + incorrect1: "removes all of the items in the array", + incorrect2: "adds an item to the end of an array and returns the array.", + incorrect3: "removes the first item from an array and returns it.", + exerciseId: 4, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: `What is the expected output of the following code? + const kings = [“King Arthur”, “Queen Elizabeth”, "King Willem Alexander”, “The Monkey King”] + console.log(kings.pop())`, + answer: "The Monkey King", + incorrect1: "King Arthur", + incorrect2: '[“King Arthur”, “Queen Elizabeth”, "King Willem Alexander”]', + incorrect3: '[“Queen Elizabeth”, "King Willem Alexander”, “The Monkey King”]', + exerciseId: 4, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: "What does the Push() accomplish?", + answer: "The push() method adds new items to the end of an array", + incorrect1: "The push() method replaces items at the end of an array", + incorrect2: "The push() method removes the first items of the array", + incorrect3: "The push() method removes items at the end of an array.", + exerciseId: 5, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: `What is the outcome of the following code? + let sports = ['soccer', 'baseball']; + let total = sports.push('football', 'swimming'); + console.log(sports`, + answer: " ['soccer', 'baseball', 'football', 'swimming']", + incorrect1: " ['soccer', 'baseball']", + incorrect2: "['football', 'swimming']", + incorrect3: "['football', 'swimming', 'soccer', 'baseball']", + exerciseId: 5, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: "What does the Shift() accomplish?", + answer: "The shift() method removes the first item of an array", + incorrect1: "The shift() method adds an item to the beginning of an array", + incorrect2: "The shift() method removes the last item of an array", + incorrect3: "The shift() method replaces the last item of an array", + exerciseId: 6, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: `What is the outcome of the following code? + let animals = ["Macaque", "Baboon", "Gorilla", "Orangutan"]; + animals.shift();`, + answer: '["Baboon", "Gorilla", "Orangutan"]', + incorrect1: '["Macaque", "Baboon", "Gorilla"]', + incorrect2: '["Orangutan", "Baboon", "Gorilla", "Macaque"]', + incorrect3: '["Gorilla", "Orangutan"]', + exerciseId: 6, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: "What does the unShift() accomplish?", + answer: "The unshift() method adds new items to the beginning of an array", + incorrect1: "The unshift() method removes the first items of an array", + incorrect2: "The unshift() method adds new items to the end of an array", + incorrect3: "The unshift() method removes the last items of an array", + exerciseId: 7, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: `What is the outcome of the following code? + let jungle = ['Monkey', 'Tiger', 'Bird']; + jungle.unshift('Snake', ‘Elephant’, ‘Hippo’)`, + answer: "[‘Snake’, ‘Elephant’, ‘Hippo’, ‘Monkey’, ‘Tiger’, ‘Bird’]", + incorrect1: "['Monkey', 'Tiger', 'Bird']", + incorrect2: "[‘Snake’, ‘Elephant’, ‘Hippo’]", + incorrect3: "['Monkey', 'Tiger', 'Bird', ‘Snake’, ‘Elephant’, ‘Hippo’]", + exerciseId: 7, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: "What does the Sort() accomplish?", + answer: "all of the above", + incorrect1: "By default, the sort() function sorts values as strings", + incorrect2: "To sort() numbers you need to add a compare function", + incorrect3: "By default, the sort() function sorts values as strings", + exerciseId: 8, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: `What is the outcome of the following code? + let numberOfBananas = [40, 100, 1, 5, 25, 10]; + numberOfBananas.sort(function(a, b){return a - b});`, + answer: "1, 5, 10, 25, 40, 100", + incorrect1: "100, 40, 25, 10, 5, 1", + incorrect2: "1, 10, 100, 25, 40, 5", + incorrect3: "5, 40, 25, 100, 10, 1", + exerciseId: 8, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: `Open Question? + Sort the age of the monkeys from oldest to youngest. + const ageMonkeys = [50, 3, 23, 12, 1]; + answer = [50,3,23,12,1]`, + answer: "ageMonkeys.sort(function(a, b){return b - a})", + incorrect1: "Only one", + incorrect2: "Only one", + incorrect3: "Only one", + exerciseId: 8, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: `Open Question? + Fill in the console.logs so the expected output is correct. + const numbers = [1, 2, 3] + console.log(YOU"RE ANSWER) + answer = 5 + console.log(YOU"RE ANSWER) + answer = [4,5,1,2,3]`, + answer: "[numbers.unshift(4, 5), numbers)]", + incorrect1: "Only one", + incorrect2: "Only one", + incorrect3: "Only one", + exerciseId: 7, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: `Open Question? + Use the .shift() method to get “Banana” out of the console.log + let fruits = ["Banana", "Orange", "Apple", "Mango"]; + answer = "Banana"`, + answer: "fruits.shift()", + incorrect1: "Only one", + incorrect2: "Only one", + incorrect3: "Only one", + exerciseId: 6, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: `Open Question? + There are 2 monkeys in the jungle; Rafiki and King Louie. + Abu, who is 15 years old, wants to join. change the following code so Abu will be added to the list of monkeys in the jungle. + let monkeys = [ + { + name: 'Rafiki', + age: 96 + }, + { + name: 'King Louie', + age: 50 + } + ]; + + // your code here + + console.log(monkeys)`, + answer: "fruits.shift()", + incorrect1: "Only one", + incorrect2: "Only one", + incorrect3: "Only one", + exerciseId: 5, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: `Open Question? + Use the map function to double all of the numbers in the array. + const array = [1,2,3,4]`, + answer: "const answer = array.map(item => item * 2)", + incorrect1: "Only one", + incorrect2: "Only one", + incorrect3: "Only one", + exerciseId: 1, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: `Open Question? + Monkeys love bananas! And hate broccoli! Please use filter to get only the bananas out of the array. + const food = [“banana", “broccoli”, “banana”, “broccoli”, “banana”, “broccoli”]`, + answer: `const answer = food.filter(item => item === “banana”`, + incorrect1: "Only one", + incorrect2: "Only one", + incorrect3: "Only one", + exerciseId: 2, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: `Open Question? + How many monkeys do we need to unscrew a light bulb? - more than 5 apparently- Please get us more than 5 monkeys out of the array. + const numberOfMonkeys= [3, 5, 7, 2, 9]`, + answer: `const answer = numberOfMonkeys.find(item => item > 5)`, + incorrect1: "Only one", + incorrect2: "Only one", + incorrect3: "Only one", + exerciseId: 3, + createdAt: new Date(), + updatedAt: new Date(), + }, + { + question: `Open Question? + Monkey Popo has levelled up his skills and now finally has become a Code Master! Please remove his name from the list of code monkeys! + const listOfMonkeys = [“Rafiki”, “Bubbles”, “Curious George”, “Popo"]`, + answer: `console.log(listOfMonkeys.pop())`, + incorrect1: "Only one", + incorrect2: "Only one", + incorrect3: "Only one", + exerciseId: 4, + createdAt: new Date(), + updatedAt: new Date(), + } ] )},