2018-10-25 20:29:56 +02:00
---
id: 587d7fb5367417b2b2512c03
title: Use the Caret-Character to Use the Latest Minor Version of a Dependency
challengeType: 2
2019-08-05 09:17:33 -07:00
forumTopicId: 301531
2021-01-13 03:31:00 +01:00
dashedName: use-the-caret-character-to-use-the-latest-minor-version-of-a-dependency
2018-10-25 20:29:56 +02:00
---
2020-11-27 19:02:05 +01:00
# --description--
Similar to how the tilde we learned about in the last challenge allows npm to install the latest PATCH for a dependency, the caret (`^` ) allows npm to install future updates as well. The difference is that the caret will allow both MINOR updates and PATCHes.
2019-03-03 12:30:44 -06:00
Your current version of moment should be "~2.10.2" which allows npm to install to the latest 2.10.x version. If you were to use the caret (^) as a version prefix instead, npm would be allowed to update to any 2.x.x version.
2019-05-14 05:00:06 -07:00
```json
"package": "^1.3.8"
```
2019-03-03 12:30:44 -06:00
This would allow updates to any 1.x.x version of the package.
2018-10-25 20:29:56 +02:00
2020-11-27 19:02:05 +01:00
# --instructions--
Use the caret (`^` ) to prefix the version of moment in your dependencies and allow npm to update it to any new MINOR release.
**Note:** The version numbers themselves should not be changed.
2018-10-25 20:29:56 +02:00
2020-11-27 19:02:05 +01:00
# --hints--
2018-10-25 20:29:56 +02:00
2020-11-27 19:02:05 +01:00
"dependencies" should include "moment"
2018-10-25 20:29:56 +02:00
2020-11-27 19:02:05 +01:00
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/package.json').then(
(data) => {
var packJson = JSON.parse(data);
assert.property(
packJson.dependencies,
'moment',
'"dependencies" does not include "moment"'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
2018-10-25 20:29:56 +02:00
```
2020-11-27 19:02:05 +01:00
"moment" version should match "^2.x.x"
2018-10-25 20:29:56 +02:00
2020-11-27 19:02:05 +01:00
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/package.json').then(
(data) => {
var packJson = JSON.parse(data);
assert.match(
packJson.dependencies.moment,
/^\^2\./,
'Wrong version of "moment". It should be ^2.10.2'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
2018-10-25 20:29:56 +02:00
2020-11-27 19:02:05 +01:00
# --solutions--
2018-10-25 20:29:56 +02:00
```js
2019-10-24 10:08:13 +05:30
/**
Backend challenges don't need solutions,
because they would need to be tested against a full working project.
Please check our contributing guidelines to learn more.
*/
2018-10-25 20:29:56 +02:00
```