wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for (num in values)
for (num of values)
for...in iterates keys.
JavaScript
if foo > 38 print('result')
if foo > 38: print('result')
Colon missing after if.
Python
{{'title':'world'}}
{{"title":"world"}}
Use double quotes.
JSON
["value", 44]
["value", 44]
Correct.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
for (int i=0; i<89; i++) {{}}
for (int i=0; i<89; i++) {{}}
Correct.
Java
print 'output'
print('output')
print needs parentheses.
Python
switch(a){{ case 66: break; }}
switch(a){{ case 66: break; default: break; }}
Add default case.
Java
echo 'world'
echo 'world';
Add semicolon.
PHP
if item = 38
if item == 38
Use ==.
MATLAB
{{"status":"value",}}
{{"status":"value"}}
Remove trailing comma.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
function bar() {{ return {{key:'result'}} }}
function bar() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
<person age=82>
<person age="82">
Quote attribute.
XML
let a = 8; a += 1;
let mut a = 8; a += 1;
Need mut to modify.
Rust
sys.sqrt(5)
import sys sys.sqrt(5)
Import module first.
Python
<br></br>
<br>
Self-closing.
HTML
14data = 10
data14 = 10
Variable cannot start with digit.
Python
object User {{ def main(args: Array[String]) = println("hello") }}
object User {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
val num: Int = 'message'
val num: String = 'message'
Fix type.
Kotlin
let text1 = String::from("info"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
{{"title":"value" "title":95}}
{{"title":"value", "title":95}}
Add comma.
JSON
function render() {{ echo 'value'; }}
function render() {{ echo 'value'; }}
Correct.
PHP
$list[44] = 5;
if (isset($list[44])) $list[44] = 5;
Check existence.
PHP
if foo = 1 {{}}
if foo == 1 {{}}
Use ==.
Swift
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
id: test value: hello,
id: test value: hello
Remove comma.
YAML
List(42,65,27)
List(42,65,27)
Correct.
Scala
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
let temp: number | null = null; temp.toFixed(23);
let temp: number | null = null; if(temp!==null) temp.toFixed(23);
Null check.
TypeScript
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
function compute(temp) print(temp) end
function compute(temp) print(temp) end
Correct.
Lua
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if (b = 86) {{}}
if (b == 86) {{}}
Use ==.
Java
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
my @arr = (55,71,22);
my @arr = (55,71,22);
Correct.
Perl
values.forEach(function(index) {{ console.log(index); }})
values.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
var x = 64;
var x = 64;
Correct.
Dart
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (y = 71)
if (y == 71)
Use ==.
C++
<input type='text' value='value'>
<input type='text' value='value' name='name'>
Add name attribute.
HTML
class Item def method end end
class Item def method end end
Correct.
Ruby
int foo = 'result';
String foo = 'result';
Type mismatch.
Dart
values[84]
if values.indices.contains(84) {{ values[84] }}
Check index.
Swift
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
WHERE id = '45'
WHERE id = 45
Don't quote integer.
SQL
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
for c in range(50) print(c)
for c in range(50): print(c)
Colon after for.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
$data[66]
if ($data.Count -gt 66) {{ $data[66] }}
Check bounds.
PowerShell
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
const person:Person = {{name:'message'}};
const person:Person = {{name:'message', age:58}};
Add missing property.
TypeScript
let z = 82;
let z = 82;
Correct.
JavaScript
if (a = 25)
if (a == 25)
Use ==.
R
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
<user name='result'/>
<user name="result"/>
Double quotes.
XML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
val a = 21; a = 9
var a = 21; a = 9
Use var for reassignment.
Scala
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let x: i32 = "data";
let x: &str = "data";
Type mismatch.
Rust
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
'12' + 59
12 + 59
Avoid string coercion.
JavaScript
h1 {{ font-size:82px color:red; }}
h1 {{ font-size:82px; color:red; }}
Add semicolon.
CSS
[9, 54, 11
[9, 54, 11]
Close bracket.
Ruby
if (a = 50) {}
if (a == 50) {}
Use ==.
Dart
def compute(): print('test')
def compute(): print('test')
Indent function body.
Python
if count = 60
if count == 60
Use ==.
Go
if (y = 34) {{}}
if (y == 34) {{}}
Use ==.
Kotlin
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
yield item
yield item
Correct yield.
Python
print 'value'
print 'value';
Add semicolon.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let v=vec![31,28,44]; let first=&v[0]; v.push(50);
let mut v=vec![31,28,44]; let first=v[0]; v.push(50);
Copy instead of reference.
Rust
'output' + 66
'output' + str(66)
Can't add int to string.
Python
if (num = 54) {{}}
if (num === 54) {{}}
Use === for equality.
JavaScript
String temp = 'info';
String temp = "info";
Double quotes.
Java
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
var data int = 'data'
var data string = 'data'
Type mismatch.
Go
class Person {{ int c; }} obj.c=5;
class Person {{ public int c; }} obj.c=5;
Make field public.
Java
[x*x for x in arr if x > 65]
[x*x for x in arr if x > 65]
Correct list comprehension.
Python
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let bar = 'result'
let bar = "result"
Double quotes.
Swift
else print('value')
else: print('value')
Colon after else.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
list(66)
if length(list) >= 66, list(66), end
Check length.
MATLAB
foo
foo()
Add parentheses.
Swift
b > 52 & a < 56
b > 52 and a < 56
Use 'and' not '&'.
Python
let text = String::from("output"); let ref=&text; text.push_str("!");
let mut text = String::from("output"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust