Skip to content

Commit 918f815

Browse files
adding template literal skilltest to the strings tasks
1 parent 2e47192 commit 918f815

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
lines changed

javascript/introduction-to-js-1/tasks/strings/marking.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let revisedQuote = quote.slice(0, index + substring.length + 1);
4545

4646
## Task 3
4747

48-
For our final string task, we return to our Green Eggs and Ham revised quote, which someone has messed up. You need to:
48+
For our next string task, we return to our Green Eggs and Ham revised quote, which someone has messed up. You need to:
4949

5050
* Fix the casing. The best way to do this is to put it all in lower case using `.toLowerCase()`, and then put the first letter in uppercase using `replace()`, `slice()`, and `toUpperCase()`. Store the new quote in `fixedQuote`.
5151
* Replace `green eggs and ham` with whatever food you really don't like using `replace()`.
@@ -64,4 +64,26 @@ fixedQuote.replace('green eggs and ham', 'pickled onions');
6464
6565
let fullStop = '.';
6666
let finalQuote = fixedQuote + fullStop;
67-
```
67+
```
68+
69+
## Task 4
70+
71+
Our final string task looks at your ability to use template literals. Your answer is expected to take the existing string literal, `myString`, turn it into a template literal, and include four placeholders in place of the asterisks:
72+
73+
* The `theorem` string.
74+
* The value of `a`.
75+
* The value of `b`.
76+
* The length of the hypotenuse, if `a` and `b` are the lengths of the two shortest sides of a right-angled triangle. You can use pythagoras' theorem to work this out.
77+
78+
Your code should look something like this:
79+
80+
```
81+
let theorem = 'Pythagorean theorem';
82+
83+
let a = 5;
84+
let b = 8;
85+
86+
let myString = `Using ${ theorem }, we can work out that that if the two shortest sides of a right-angled triangle have lengths of ${ a } and ${ b }, the length of the hypotenuse is ${ Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)) }.`;
87+
```
88+
89+
You could also a simpler form of the fourth placeholder, something like `${ Math.sqrt((a * a) + (b * b)) }`.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>Strings: Task 4</title>
6+
<style>
7+
p {
8+
color: purple;
9+
margin: 0.5em 0;
10+
}
11+
12+
* {
13+
box-sizing: border-box;
14+
}
15+
</style>
16+
<link rel="stylesheet" href="../styles.css" />
17+
</head>
18+
19+
<body>
20+
21+
<section class="preview">
22+
23+
24+
25+
</section>
26+
27+
</body>
28+
<script>
29+
let theorem = 'Pythagorean theorem';
30+
31+
let a = 5;
32+
let b = 8;
33+
34+
let myString = 'Using *, we can work out that that if the two shortest sides of a right-angled triangle have lengths of * and *, the length of the hypotenuse is *.';
35+
36+
37+
// Don't edit the code below here!
38+
39+
const section = document.querySelector('section');
40+
41+
let para1 = document.createElement('p');
42+
para1.textContent = myString;
43+
section.appendChild(para1);
44+
</script>
45+
46+
</html>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Strings: Task 4</title>
6+
<link rel="stylesheet" href="../styles.css" />
7+
<style>
8+
* {
9+
box-sizing: border-box;
10+
}
11+
12+
p {
13+
color: purple;
14+
margin: 0.5em 0;
15+
}
16+
</style>
17+
</head>
18+
19+
<body>
20+
<section class="preview">
21+
22+
23+
24+
</section>
25+
26+
<textarea class="playable playable-js" style="height: 220px;">
27+
let theorem = 'Pythagorean theorem';
28+
29+
let a = 5;
30+
let b = 8;
31+
32+
let myString = 'Using *, we can work out that that if the two shortest sides of a right-angled triangle have lengths of * and *, the length of the hypotenuse is *.';
33+
34+
// Don't edit the code below here!
35+
36+
section.innerHTML = ' ';
37+
let para1 = document.createElement('p');
38+
para1.textContent = myString;
39+
40+
section.appendChild(para1);
41+
</textarea>
42+
43+
<div class="playable-buttons">
44+
<input id="reset" type="button" value="Reset" />
45+
</div>
46+
</body>
47+
<script class="editable"></script>
48+
<script src="../playable.js"></script>
49+
</html>

0 commit comments

Comments
 (0)