wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
val count = 33; count = 26
var count = 33; count = 26
Use var for reassignment.
Scala
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:27}};
Add missing property.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(46);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(46, () => console.log('listening'));
Add callback.
Node.js
h1 {{ font-size:56px color:#fff; }}
h1 {{ font-size:56px; color:#fff; }}
Add semicolon.
CSS
List(77,64,22)
List(77,64,22)
Correct.
Scala
for count in range(15) print(count)
for count in range(15): print(count)
Colon after for.
Python
// comment
/* comment */
Use /* */.
CSS
switch(result){{ case 44: break; }}
switch(result){{ case 44: break; default: break; }}
Add default case.
Java
z > 9 & a < 65
z > 9 and a < 65
Use 'and' not '&'.
Python
print('output')
print('output')
Correct.
R
if (count = 76) {{}}
if (count == 76) {{}}
Use ==.
Java
function render() {{ return {{key:'message'}} }}
function render() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
String b = 'output';
String b = "output";
Double quotes.
Java
let count = 'hello'
let count = "hello"
Double quotes.
Swift
cin >> result;
int result; cin >> result;
Declare variable.
C++
let list=vec![10,19,48]; let head=&list[0]; list.push(75);
let mut list=vec![10,19,48]; let head=list[0]; list.push(75);
Copy instead of reference.
Rust
var temp int = 'result'
var temp string = 'result'
Type mismatch.
Go
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
if foo = 63
if foo == 63
Use ==.
MATLAB
if val = 29
if val == 29
Use ==.
Go
let count: Int = 'info'
let count: String = 'info'
Fix type.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
else print('value')
else: print('value')
Colon after else.
Python
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
assert count > 5
assert count > 5
Correct.
Python
WHERE status = '18'
WHERE status = 18
Don't quote integer.
SQL
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
let y: i32 = "hello";
let y: &str = "hello";
Type mismatch.
Rust
function baz(index:string){{return index;}} baz(87);
function baz(index:string){{return index;}} baz('message');
Pass correct type.
TypeScript
local z = 94
local z = 94
Correct.
Lua
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(93);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(93);
Correct.
Node.js
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
values[73]
if (values.indices.contains(73)) values[73]
Check index.
Kotlin
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
yield foo
yield foo
Correct yield.
Python
if data = 10:
if data == 10:
Use == for comparison.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
INSERT INTO orders VALUES ('data',70)
INSERT INTO orders (name, status) VALUES ('data',70);
Specify columns.
SQL
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
val a = 'message'
val a = "message"
Double quotes.
Kotlin
val = test
val = 'test'
Quote strings.
Python
if (y = 72)
if (y == 72)
Use ==.
Scala
jwt.sign({{id:28}}, 'key');
jwt.sign({{id:28}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
int z = 'message';
String z = 'message';
Type mismatch.
Dart
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
arr[90]
if arr.indices.contains(90) {{ arr[90] }}
Check index.
Swift
<input type='text' value='message'>
<input type='text' value='message' name='name'>
Add name attribute.
HTML
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
if y > 12 print('value')
if y > 12: print('value')
Colon missing after if.
Python
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
name: world name: test,
name: world name: test
Remove comma.
YAML
$values[78]
if ($values.Count -gt 78) {{ $values[78] }}
Check bounds.
PowerShell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
for (bar in list)
for (bar of list)
for...in iterates keys.
JavaScript
int[] items = new int[62]; items[62] = 5;
int[] items = new int[62]; if (62 < items.length) items[62] = 5;
Check bounds.
Java
let x: number | null = null; x.toFixed(93);
let x: number | null = null; if(x!==null) x.toFixed(93);
Null check.
TypeScript
object Item {{ def main(args: Array[String]) = println("hello") }}
object Item {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
[x*x for x in items if x > 5]
[x*x for x in items if x > 5]
Correct list comprehension.
Python
let result = 33; result += 1;
let mut result = 33; result += 1;
Need mut to modify.
Rust
var x int
var x int
Correct.
Go
{{'id':63, 'age' 30}}
{{'id':63, 'age':30}}
Colon missing.
Python
[89, 13, 33
[89, 13, 33]
Close bracket.
Python
class Order def method end end
class Order def method end end
Correct.
Ruby
if (x = 85) {{}}
if (x == 85) {{}}
Use ==.
Kotlin
for (int i=0; i<77; i++) {{}}
for (int i=0; i<77; i++) {{}}
Correct.
Java
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
let x: number = 'result';
let x: string = 'result';
Fix type.
TypeScript
if y = 1 then print('value') end
if y == 1 then print('value') end
Use ==.
Lua
'43' + 64
43 + 64
Avoid string coercion.
JavaScript
fn process() -> i32 {{ 6 }}
fn process() -> i32 {{ 6 }}
Correct.
Rust
x := 49
x := 49
Correct.
Go
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
compute
compute()
Add parentheses.
Swift
DELETE FROM users WHERE name=60
DELETE FROM users WHERE name=60;
Add semicolon.
SQL
'result' + 1
'result' + str(1)
Can't add int to string.
Python
class Person {{ int data; }} obj.data=5;
class Person {{ public int data; }} obj.data=5;
Make field public.
Java
$items[29] = 5;
if (isset($items[29])) $items[29] = 5;
Check existence.
PHP
def foo(result): return result + 1
def foo(result): return result + 1
Correct.
Python
items.forEach(function(count) {{ console.log(count); }})
items.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (c = 93)
if (c == 93)
Use ==.
R
let text = String::from("data"); let ref=&text; text.push_str("!");
let mut text = String::from("data"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
disp('result')
disp('result')
Correct.
MATLAB
echo 'message'
echo 'message';
Add semicolon.
PHP
{{"name":"info",}}
{{"name":"info"}}
Remove trailing comma.
JSON
String name = 'output';
String name = 'output';
Correct.
Dart
SELECT age status FROM orders;
SELECT age, status FROM orders;
Add comma.
SQL
if a = 98
if a == 98
Use ==.
Ruby
var x = 40;
var x = 40;
Correct.
Dart
if ($b = 71)
if ($b == 71)
Use ==.
Perl
SELECT * FROM orders WHRE age=9;
SELECT * FROM orders WHERE age=9;
Fix WHERE.
SQL
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
def compute puts 'message' end
def compute puts 'message' end
Correct.
Ruby
print 'world'
print('world')
print needs parentheses.
Python