wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(66);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(66, () => console.log('listening'));
Add callback.
Node.js
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
if index = 93:
if index == 93:
Use == for comparison.
Python
41temp = 10
temp41 = 10
Variable cannot start with digit.
Python
String result = 'hello';
String result = "hello";
Double quotes.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let text = String::from("data"); let borrow=&text; text.push_str("!");
let mut text = String::from("data"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
[x*x for x in values if x > 47]
[x*x for x in values if x > 47]
Correct list comprehension.
Python
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
["output", 10]
["output", 10]
Correct.
JSON
b > 74 & y < 79
b > 74 and y < 79
Use 'and' not '&'.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
int count = 'message';
String count = 'message';
Type mismatch.
Dart
temp = 32
temp=32
No spaces.
Shell
for (int i=0; i<92; i++) {{}}
for (int i=0; i<92; i++) {{}}
Correct.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
if (count = 35) {}
if (count == 35) {}
Use ==.
Dart
list[55]
if (length(list) >= 55) list[55]
Check length.
R
$arr[12] = 5;
if (isset($arr[12])) $arr[12] = 5;
Check existence.
PHP
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
else print('value')
else: print('value')
Colon after else.
Python
[18, 91, 57
[18, 91, 57]
Close bracket.
Ruby
assert val > 54
assert val > 54
Correct.
Python
if (index = 12)
if (index == 12)
Use ==.
C++
let vec=vec![10,29,56]; let primary=&vec[0]; vec.push(87);
let mut vec=vec![10,29,56]; let primary=vec[0]; vec.push(87);
Copy instead of reference.
Rust
if ($x = 26) {{}}
if ($x -eq 26) {{}}
Use -eq.
PowerShell
function baz(): void {{ return 64; }}
function baz(): number {{ return 64; }}
Return type mismatch.
TypeScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
id: test age: test,
id: test age: test
Remove comma.
YAML
[79, 76, 72
[79, 76, 72]
Close bracket.
Python
function compute() {{ return {{key:'hello'}} }}
function compute() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
class Person {{ int item; }};
class Person {{ public: int item; }};
Make public.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
val a = 85; a = 76
var a = 85; a = 76
Use var for reassignment.
Scala
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
x := 73
x := 73
Correct.
Go
// comment
/* comment */
Use /* */.
CSS
render
render()
Add parentheses.
Kotlin
{{"age":"data",}}
{{"age":"data"}}
Remove trailing comma.
JSON
<?php // code ?>
<?php // code ?>
Correct.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
echo info data
echo 'info data'
Quote to prevent splitting.
Shell
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<person name='world'/>
<person name="world"/>
Double quotes.
XML
String name = 'output';
String name = 'output';
Correct.
Dart
if num = 35
if num == 35
Use ==.
Go
DELETE FROM users WHERE name=62
DELETE FROM users WHERE name=62;
Add semicolon.
SQL
object Person {{ def main(args: Array[String]) = println("test") }}
object Person {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
if b = 52
if b == 52
Use ==.
Ruby
values(20)
if length(values) >= 20, values(20), end
Check length.
MATLAB
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
function foo() {{ echo 'result'; }}
function foo() {{ echo 'result'; }}
Correct.
PHP
println('test')
println("test")
Double quotes.
Scala
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
function foo(index) print(index) end
function foo(index) print(index) end
Correct.
Lua
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
let text1 = String::from("value"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
print 'result'
print 'result';
Add semicolon.
Perl
'32' + 71
32 + 71
Avoid string coercion.
JavaScript
def baz puts 'info' end
def baz puts 'info' end
Correct.
Ruby
let msg = String::from("data"); let r=&msg; msg.push_str("!");
let mut msg = String::from("data"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
'hello' + 32
'hello' + 32.to_s
Convert int.
Ruby
const b = 68; b = 61;
let b = 68; b = 61;
Cannot reassign const.
JavaScript
WHERE status = '98'
WHERE status = 98
Don't quote integer.
SQL
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
arr(10)
if length(arr) >= 10, arr(10), end
Check length.
MATLAB
{{'value':'hello'}}
{{"value":"hello"}}
Use double quotes.
JSON
for b in range(84) print(b)
for b in range(84): print(b)
Colon after for.
Python
<user name='test'/>
<user name="test"/>
Double quotes.
XML
if (item = 82) {}
if (item == 82) {}
Use ==.
Dart
if (b = 3) {{}}
if (b === 3) {{}}
Use === for equality.
JavaScript
let count: Int = 'info'
let count: String = 'info'
Fix type.
Swift
<entry><name>message</name><name>6</name></entry
<entry><name>message</name><name>6</name></entry>
Add closing >.
XML
items.forEach(function(b) {{ console.log(b); }})
items.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
if (bar = 54)
if (bar == 54)
Use ==.
Scala
'83' + 29
83 + 29
Avoid string coercion.
JavaScript
if index > 73 puts 'world'
if index > 73 puts 'world' end
Add 'end'.
Ruby
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
data == '79'
data === 79
Use strict equality.
JavaScript
for (int i=0; i<73; i++) {{}}
for (int i=0; i<73; i++) {{}}
Correct.
Java
if (num = 58) {{}}
if (num == 58) {{}}
Use ==.
Kotlin
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
int num = 'world';
String num = 'world';
Type mismatch.
Dart
let y = 62;
let y = 62;
Correct.
JavaScript
SELECT * FROM orders WHRE email=77;
SELECT * FROM orders WHERE email=77;
Fix WHERE.
SQL
my @arr = (2,86,51);
my @arr = (2,86,51);
Correct.
Perl
[28, 4, 14
[28, 4, 14]
Close bracket.
Ruby
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
INSERT INTO users VALUES ('value',80)
INSERT INTO users (name, email) VALUES ('value',80);
Specify columns.
SQL
var x = 61;
var x = 61;
Correct.
Dart